Skip to content

Commit 26678ed

Browse files
committed
DRY up Client building
1 parent cf44c55 commit 26678ed

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/client.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ pub struct VssClient {
2626
impl VssClient {
2727
/// Constructs a [`VssClient`] using `base_url` as the VSS server endpoint.
2828
pub fn new(base_url: String) -> Self {
29-
let client = Client::builder()
30-
.timeout(DEFAULT_TIMEOUT)
31-
.connect_timeout(DEFAULT_TIMEOUT)
32-
.read_timeout(DEFAULT_TIMEOUT)
33-
.build()
34-
.unwrap();
29+
let client = build_client();
3530
Self::from_client(base_url, client)
3631
}
3732

@@ -44,12 +39,7 @@ impl VssClient {
4439
///
4540
/// HTTP headers will be provided by the given `header_provider`.
4641
pub fn new_with_headers(base_url: String, header_provider: Arc<dyn VssHeaderProvider>) -> Self {
47-
let client = Client::builder()
48-
.timeout(DEFAULT_TIMEOUT)
49-
.connect_timeout(DEFAULT_TIMEOUT)
50-
.read_timeout(DEFAULT_TIMEOUT)
51-
.build()
52-
.unwrap();
42+
let client = build_client();
5343
Self { base_url, client, header_provider }
5444
}
5545

@@ -137,3 +127,12 @@ impl VssClient {
137127
}
138128
}
139129
}
130+
131+
fn build_client() -> Client {
132+
Client::builder()
133+
.timeout(DEFAULT_TIMEOUT)
134+
.connect_timeout(DEFAULT_TIMEOUT)
135+
.read_timeout(DEFAULT_TIMEOUT)
136+
.build()
137+
.unwrap()
138+
}

0 commit comments

Comments
 (0)