From 913d5b68ec84aec0607764850a2d8bdea5ebe5c6 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 13 Oct 2022 10:15:05 -0400 Subject: [PATCH] chanmgr: Remove RegistryAsFactory. Since there is no longer a blanket implementation of ChannelFactory for TransportHelper, we no longer need a separate type here. --- crates/tor-chanmgr/src/factory/registry.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/crates/tor-chanmgr/src/factory/registry.rs b/crates/tor-chanmgr/src/factory/registry.rs index ab8000fdd..1066cdf09 100644 --- a/crates/tor-chanmgr/src/factory/registry.rs +++ b/crates/tor-chanmgr/src/factory/registry.rs @@ -8,7 +8,10 @@ use crate::Error; use super::ChannelFactory; -/// An object that knows about one or more ChannelFactories. +/// An object that knows about one or more [`ChannelFactory`]s. +/// +/// It can be used itself as a `ChannelFactory`, to open connections to a given +/// channel target depending on its configured [`TransportId`]. pub trait TransportRegistry { /// Return a ChannelFactory that can make connections via a chosen /// transport, if we know one. @@ -17,20 +20,12 @@ pub trait TransportRegistry { fn get_factory(&self, transport: &TransportId) -> Option<&(dyn ChannelFactory + Sync)>; } -/// Helper type: Wrap a `TransportRegistry` so that it can be used as a -/// `ChannelFactory`. -/// -/// (This has to be a new type, or else the blanket implementation of -/// `ChannelFactory` for `TransportHelper` would conflict.) -#[derive(Clone, Debug)] -pub(crate) struct RegistryAsFactory(R); - #[async_trait] -impl ChannelFactory for RegistryAsFactory { +impl ChannelFactory for R { async fn connect_via_transport(&self, target: &OwnedChanTarget) -> crate::Result { let method = target.chan_method(); let id = method.transport_id(); - let factory = self.0.get_factory(&id).ok_or(Error::NoSuchTransport(id))?; + let factory = self.get_factory(&id).ok_or(Error::NoSuchTransport(id))?; factory.connect_via_transport(target).await }