Skip to content

Commit ce1e243

Browse files
Merge #30: Derive Clone and implement {url, client} for AsyncClient
5553784 Add `BlockingClient::{url, agent}` (Hirrolot) 80f648b Derive `Clone` and implement `{url, client}` for `AsyncClient` (Hirrolot) Pull request description: Summary: - `#[derive(Clone)]` for `AsyncClient` so that it can now be cloned. The implementation should be cheap because `reqwest::Client` is wrapped in `Arc` automatically, and the `url` field should not be large either. - Add the `{url, client}` getters. They are helpful when you want to obtain data from which `AsyncClient` was constructed and don't want to pass these parameters around your code. Top commit has no ACKs. Tree-SHA512: bd5c1843a010a72993e9e1f25e0898bc4c089ac4cb5fcbb4781fa85a8f98f901fabe0692182335cc681ba98409960072f4ea92bd599cc2a1b7ef3feca42e2cde
2 parents cb45d36 + 5553784 commit ce1e243

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/async.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use reqwest::{Client, StatusCode};
2626

2727
use crate::{BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus};
2828

29-
#[derive(Debug)]
29+
#[derive(Debug, Clone)]
3030
pub struct AsyncClient {
3131
url: String,
3232
client: Client,
@@ -323,4 +323,14 @@ impl AsyncClient {
323323
.json()
324324
.await?)
325325
}
326+
327+
/// Get the underlying base URL.
328+
pub fn url(&self) -> &str {
329+
&self.url
330+
}
331+
332+
/// Get the underlying [`Client`].
333+
pub fn client(&self) -> &Client {
334+
&self.client
335+
}
326336
}

src/blocking.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,16 @@ impl BlockingClient {
357357

358358
Ok(self.agent.get(&url).call()?.into_json()?)
359359
}
360+
361+
/// Get the underlying base URL.
362+
pub fn url(&self) -> &str {
363+
&self.url
364+
}
365+
366+
/// Get the underlying [`Agent`].
367+
pub fn agent(&self) -> &Agent {
368+
&self.agent
369+
}
360370
}
361371

362372
fn is_status_not_found(status: u16) -> bool {

0 commit comments

Comments
 (0)