Trait tor_rpcbase::obj::Object

source ·
pub trait Object: DowncastSync + Send + Sync + 'static {
    // Provided methods
    fn expose_outside_of_session(&self) -> bool { ... }
    fn get_cast_table(&self) -> &CastTable { ... }
}
Expand description

An object in our RPC system to which methods can be addressed.

You shouldn’t implement this trait yourself; instead, use the derive_deftly(Object).

See the documentation for derive_deftly(Object) for examples of how to declare and downcast Objects.

Provided Methods§

source

fn expose_outside_of_session(&self) -> bool

Return true if this object should be given an identifier that allows it to be used outside of the session that generated it.

Currently, the only use for such IDs in arti is identifying stream contexts in when opening a SOCKS connection: When an application opens a stream, it needs to declare what RPC context (like a TorClient) it’s using, which requires that some identifier for that context exist outside of the RPC session that owns it.

source

fn get_cast_table(&self) -> &CastTable

Return a CastTable that can be used to downcast a dyn Object of this type into various kinds of dyn Trait references.

The default implementation of this method declares that the Object can’t be downcast into any traits.

You should not implement this method yourself; instead use derive_deftly(Object).

Implementations§

source§

impl dyn Object

source

pub fn is<__T: Object>(&self) -> bool

Returns true if the trait object wraps an object of type __T.

source

pub fn downcast<__T: Object>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn’t.

source

pub fn downcast_rc<__T: Object>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>

Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of type __T. Returns the original Rc-ed trait if it isn’t.

source

pub fn downcast_ref<__T: Object>(&self) -> Option<&__T>

Returns a reference to the object within the trait object if it is of type __T, or None if it isn’t.

source

pub fn downcast_mut<__T: Object>(&mut self) -> Option<&mut __T>

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn’t.

source

pub fn downcast_arc<__T: Object + Any + Send + Sync>( self: Arc<Self> ) -> Result<Arc<__T>, Arc<Self>>

Returns an Arc-ed object from an Arc-ed trait object if the underlying object is of type __T. Returns the original Arc-ed trait if it isn’t.

Trait Implementations§

source§

impl ObjectRefExt for dyn Object

source§

fn cast_to_trait<T: ?Sized + 'static>(&self) -> Option<&T>

Try to cast this Object to a T. On success, return a reference to T; on failure, return None.

Implementors§