diff --git a/crates/tor-netdir/src/lib.rs b/crates/tor-netdir/src/lib.rs index 4cc468d04..d3c134acf 100644 --- a/crates/tor-netdir/src/lib.rs +++ b/crates/tor-netdir/src/lib.rs @@ -279,7 +279,7 @@ pub enum DirEvent { /// An object that can provide [`NetDir`]s, as well as inform consumers when /// they might have changed. -pub trait NetDirProvider { +pub trait NetDirProvider: UpcastArcNetDirProvider { /// Return a handle to our latest directory, if we have one. fn latest_netdir(&self) -> Option>; @@ -305,6 +305,32 @@ where } } +/// Helper trait: allows any `Arc` to be upcast to a `Arc` if X is an implementation or supertrait of NetDirProvider. +/// +/// This trait exists to work around a limitation in rust: when trait upcasting +/// coercion is stable, this will be unnecessary. +/// +/// The Rust tracking issue is . +pub trait UpcastArcNetDirProvider { + /// Return a view of this object as an `Arc` + fn upcast_arc<'a>(self: Arc) -> Arc + where + Self: 'a; +} + +impl UpcastArcNetDirProvider for T +where + T: NetDirProvider + Sized, +{ + fn upcast_arc<'a>(self: Arc) -> Arc + where + Self: 'a, + { + self + } +} + /// A partially build NetDir -- it can't be unwrapped until it has /// enough information to build safe paths. #[derive(Debug, Clone)]