Skip to content

Commit

Permalink
Change builder to not need runtime struct to be passed in
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenperera committed Oct 15, 2024
1 parent 0049215 commit d1e2184
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@

#![allow(clippy::result_large_err)]

use std::collections::HashMap;
use std::fmt;
use std::num::TryFromIntError;
use std::time::Duration;
use std::{collections::HashMap, marker::PhantomData};

pub mod api;

Expand Down Expand Up @@ -137,7 +137,7 @@ pub struct Builder<R = DefaultRuntime> {
/// Max retries
pub max_retries: usize,
/// Async runtime, trait must implement `sleep` function, default is `tokio`
pub runtime: R,
pub runtime: PhantomData<R>,
}

impl Builder {
Expand All @@ -149,7 +149,7 @@ impl Builder {
timeout: None,
headers: HashMap::new(),
max_retries: DEFAULT_MAX_RETRIES,
runtime: DefaultRuntime,
runtime: PhantomData,
}
}

Expand All @@ -164,16 +164,16 @@ impl<R: Runtime> Builder<R>
where
R: Runtime,
{
/// New with runtime
/// Instantiate a new builder, with a custom runtime
#[cfg(feature = "async")]
pub fn new_with_runtime(base_url: &str, runtime: R) -> Self {
pub fn new_custom_runtime(base_url: &str) -> Self {
Builder {
base_url: base_url.to_string(),
proxy: None,
timeout: None,
headers: HashMap::new(),
max_retries: DEFAULT_MAX_RETRIES,
runtime,
runtime: PhantomData,
}
}

Expand Down Expand Up @@ -1046,10 +1046,8 @@ mod test {
#[cfg(not(feature = "tokio"))]
#[test]
fn use_with_custom_runtime() {
let builder = Builder::<TestRuntime>::new_with_runtime(
"https://blockstream.info/testnet/api",
TestRuntime,
);
let builder =
Builder::<TestRuntime>::new_with_runtime("https://blockstream.info/testnet/api");

let client = builder.build_async();
assert!(client.is_ok());
Expand Down

0 comments on commit d1e2184

Please sign in to comment.