Skip to content

Commit 97381da

Browse files
committed
DRY up Client building
1 parent ad0c024 commit 97381da

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
@@ -32,12 +32,7 @@ where
3232
impl<R: RetryPolicy<E = VssError>> VssClient<R> {
3333
/// Constructs a [`VssClient`] using `base_url` as the VSS server endpoint.
3434
pub fn new(base_url: String, retry_policy: R) -> Self {
35-
let client = Client::builder()
36-
.timeout(DEFAULT_TIMEOUT)
37-
.connect_timeout(DEFAULT_TIMEOUT)
38-
.read_timeout(DEFAULT_TIMEOUT)
39-
.build()
40-
.unwrap();
35+
let client = build_client();
4136
Self::from_client(base_url, client, retry_policy)
4237
}
4338

@@ -57,12 +52,7 @@ impl<R: RetryPolicy<E = VssError>> VssClient<R> {
5752
pub fn new_with_headers(
5853
base_url: String, retry_policy: R, header_provider: Arc<dyn VssHeaderProvider>,
5954
) -> Self {
60-
let client = Client::builder()
61-
.timeout(DEFAULT_TIMEOUT)
62-
.connect_timeout(DEFAULT_TIMEOUT)
63-
.read_timeout(DEFAULT_TIMEOUT)
64-
.build()
65-
.unwrap();
55+
let client = build_client();
6656
Self { base_url, client, retry_policy, header_provider }
6757
}
6858

@@ -173,3 +163,12 @@ impl<R: RetryPolicy<E = VssError>> VssClient<R> {
173163
}
174164
}
175165
}
166+
167+
fn build_client() -> Client {
168+
Client::builder()
169+
.timeout(DEFAULT_TIMEOUT)
170+
.connect_timeout(DEFAULT_TIMEOUT)
171+
.read_timeout(DEFAULT_TIMEOUT)
172+
.build()
173+
.unwrap()
174+
}

0 commit comments

Comments
 (0)