chanmgr: Remove RegistryAsFactory.

Since there is no longer a blanket implementation of ChannelFactory
for TransportHelper, we no longer need a separate type here.
This commit is contained in:
Nick Mathewson 2022-10-13 10:15:05 -04:00
parent fe2d44d10a
commit 913d5b68ec
1 changed files with 6 additions and 11 deletions

View File

@ -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: TransportRegistry>(R);
#[async_trait]
impl<R: TransportRegistry + Sync> ChannelFactory for RegistryAsFactory<R> {
impl<R: TransportRegistry + Sync> ChannelFactory for R {
async fn connect_via_transport(&self, target: &OwnedChanTarget) -> crate::Result<Channel> {
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
}