Skip to content

Commit bde1f05

Browse files
committed
fix: use bon as builder for ClientOption struct
1 parent 5864a80 commit bde1f05

3 files changed

Lines changed: 14 additions & 16 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/charon/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ serde.workspace = true
2525
serde_json.workspace = true
2626
hex.workspace = true
2727
k256.workspace = true
28+
bon.workspace = true
2829
charon-cluster = { workspace = true }
2930
charon-k1util = { workspace = true }
3031
charon-crypto = { workspace = true }

crates/charon/src/obolapi/client.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
use std::time::Duration;
77

8+
use bon::Builder;
89
use charon_cluster::lock::Lock;
910
use reqwest::{Method, StatusCode};
1011
use url::Url;
@@ -28,25 +29,12 @@ pub struct Client {
2829
}
2930

3031
/// Options for configuring the Obol API client.
31-
#[derive(Debug, Default, Clone)]
32+
#[derive(Debug, Default, Clone, Builder)]
3233
pub struct ClientOptions {
33-
/// HTTP request timeout (defaults to 10 seconds).
34+
/// Optional HTTP request timeout override (defaults to 10 seconds).
3435
pub timeout: Option<Duration>,
3536
}
3637

37-
impl ClientOptions {
38-
/// Creates new default client options.
39-
pub fn new() -> Self {
40-
Self::default()
41-
}
42-
43-
/// Sets the HTTP request timeout for all Client calls.
44-
pub fn timeout(mut self, timeout: Duration) -> Self {
45-
self.timeout = Some(timeout);
46-
self
47-
}
48-
}
49-
5038
impl Client {
5139
/// Creates a new Obol API client.
5240
pub fn new(url_str: &str, options: ClientOptions) -> Result<Self> {
@@ -231,7 +219,15 @@ mod tests {
231219

232220
#[test]
233221
fn test_new_client_valid_url() {
234-
assert!(Client::new("https://api.obol.tech", ClientOptions::default()).is_ok());
222+
assert!(
223+
Client::new(
224+
"https://api.obol.tech",
225+
ClientOptions::builder()
226+
.timeout(Duration::from_secs(10))
227+
.build()
228+
)
229+
.is_ok()
230+
);
235231
}
236232

237233
#[test]

0 commit comments

Comments
 (0)