Skip to content

Commit eb19781

Browse files
committed
Change builder to not need runtime struct to be passed in
1 parent 8ead24a commit eb19781

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/lib.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666
6767
#![allow(clippy::result_large_err)]
6868

69-
use std::collections::HashMap;
7069
use std::fmt;
7170
use std::num::TryFromIntError;
7271
use std::time::Duration;
72+
use std::{collections::HashMap, marker::PhantomData};
7373

7474
pub mod api;
7575

@@ -137,7 +137,7 @@ pub struct Builder<R = DefaultRuntime> {
137137
/// Max retries
138138
pub max_retries: usize,
139139
/// Async runtime, trait must implement `sleep` function, default is `tokio`
140-
pub runtime: R,
140+
pub runtime: PhantomData<R>,
141141
}
142142

143143
impl Builder {
@@ -149,7 +149,7 @@ impl Builder {
149149
timeout: None,
150150
headers: HashMap::new(),
151151
max_retries: DEFAULT_MAX_RETRIES,
152-
runtime: DefaultRuntime,
152+
runtime: PhantomData,
153153
}
154154
}
155155

@@ -164,16 +164,16 @@ impl<R: Runtime> Builder<R>
164164
where
165165
R: Runtime,
166166
{
167-
/// New with runtime
167+
/// Instantiate a new builder, with a custom runtime
168168
#[cfg(feature = "async")]
169-
pub fn new_with_runtime(base_url: &str, runtime: R) -> Self {
169+
pub fn new_custom_runtime(base_url: &str) -> Self {
170170
Builder {
171171
base_url: base_url.to_string(),
172172
proxy: None,
173173
timeout: None,
174174
headers: HashMap::new(),
175175
max_retries: DEFAULT_MAX_RETRIES,
176-
runtime,
176+
runtime: PhantomData,
177177
}
178178
}
179179

@@ -1046,10 +1046,8 @@ mod test {
10461046
#[cfg(not(feature = "tokio"))]
10471047
#[test]
10481048
fn use_with_custom_runtime() {
1049-
let builder = Builder::<TestRuntime>::new_with_runtime(
1050-
"https://blockstream.info/testnet/api",
1051-
TestRuntime,
1052-
);
1049+
let builder =
1050+
Builder::<TestRuntime>::new_with_runtime("https://blockstream.info/testnet/api");
10531051

10541052
let client = builder.build_async();
10551053
assert!(client.is_ok());

0 commit comments

Comments
 (0)