diff --git a/transports/dns/CHANGELOG.md b/transports/dns/CHANGELOG.md index 692c0f966b7..386379ae389 100644 --- a/transports/dns/CHANGELOG.md +++ b/transports/dns/CHANGELOG.md @@ -1,5 +1,9 @@ ## 0.41.0 - unreleased +- Make `tokio::Transport::custom` and `async_std::Transport::custom` constructors infallible. + See [PR 4464]. + +[PR 4464]: https://github.com/libp2p/rust-libp2p/pull/4464 ## 0.40.1 diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index b27b14a77c0..3fd5ae9dc4d 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -75,19 +75,15 @@ pub mod async_std { /// Creates a new [`Transport`] from the OS's DNS configuration and defaults. pub async fn system(inner: T) -> Result, io::Error> { let (cfg, opts) = system_conf::read_system_conf()?; - Self::custom(inner, cfg, opts).await + Ok(Self::custom(inner, cfg, opts).await) } /// Creates a [`Transport`] with a custom resolver configuration and options. - pub async fn custom( - inner: T, - cfg: ResolverConfig, - opts: ResolverOpts, - ) -> Result, io::Error> { - Ok(Transport { + pub async fn custom(inner: T, cfg: ResolverConfig, opts: ResolverOpts) -> Transport { + Transport { inner: Arc::new(Mutex::new(inner)), resolver: async_std_resolver::resolver(cfg, opts).await, - }) + } } } } @@ -108,9 +104,9 @@ pub mod tokio { impl Transport { /// Creates a new [`Transport`] from the OS's DNS configuration and defaults. - pub fn system(inner: T) -> Result, std::io::Error> { + pub fn system(inner: T) -> Result, std::io::Error> { let (cfg, opts) = system_conf::read_system_conf()?; - Self::custom(inner, cfg, opts) + Ok(Self::custom(inner, cfg, opts)) } /// Creates a [`Transport`] with a custom resolver configuration @@ -119,12 +115,11 @@ pub mod tokio { inner: T, cfg: trust_dns_resolver::config::ResolverConfig, opts: trust_dns_resolver::config::ResolverOpts, - ) -> Result, std::io::Error> { - // TODO: Make infallible in next breaking release. Or deprecation? - Ok(Transport { + ) -> Transport { + Transport { inner: Arc::new(Mutex::new(inner)), resolver: TokioAsyncResolver::tokio(cfg, opts), - }) + } } } } @@ -764,8 +759,7 @@ mod tests { let config = ResolverConfig::quad9(); let opts = ResolverOpts::default(); async_std_crate::task::block_on( - async_std::Transport::custom(CustomTransport, config, opts) - .then(|dns| run(dns.unwrap())), + async_std::Transport::custom(CustomTransport, config, opts).then(run), ); } @@ -781,9 +775,7 @@ mod tests { .build() .unwrap(); - rt.block_on(run( - tokio::Transport::custom(CustomTransport, config, opts).unwrap() - )); + rt.block_on(run(tokio::Transport::custom(CustomTransport, config, opts))); } } }