Created
November 2, 2022 06:37
-
-
Save Seeker14491/3e566ed1e5714ae013296996ce69732e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::error::Error; | |
use ethers_providers::Provider; | |
trait ClientGeneric<T> | |
where | |
for<'a> &'a str: TryInto<Provider<T>>, | |
for<'a> <&'a str as TryInto<Provider<T>>>::Error: Error + 'static, | |
{ | |
fn get_client(&self, url: &str) -> Result<Provider<T>, Box<dyn Error>> { | |
Ok(url.try_into()?) | |
} | |
} | |
impl<T, U> ClientGeneric<U> for T | |
where | |
for<'a> &'a str: TryInto<Provider<U>>, | |
for<'a> <&'a str as TryInto<Provider<U>>>::Error: Error + 'static, | |
{ | |
} | |
struct Test; | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
#[test] | |
fn test_get_client_generic() { | |
let test = Test {}; | |
let _client = test.get_client("http://localhost:8080").unwrap(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment