pub trait Object:
DowncastSync
+ Send
+ Sync
+ 'static {
// Provided methods
fn expose_outside_of_session(&self) -> bool { ... }
fn get_cast_table(&self) -> &CastTable { ... }
fn delegate(&self) -> Option<Arc<dyn Object>> { ... }
}
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 Object
s.
Provided Methods§
Sourcefn expose_outside_of_session(&self) -> bool
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.
Sourcefn get_cast_table(&self) -> &CastTable
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
impl dyn Object
Sourcepub fn is<__T: Object>(&self) -> bool
pub fn is<__T: Object>(&self) -> bool
Returns true if the trait object wraps an object of type __T
.
Sourcepub fn downcast<__T: Object>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
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.
Sourcepub fn downcast_rc<__T: Object>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
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.
Sourcepub fn downcast_ref<__T: Object>(&self) -> Option<&__T>
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.
Sourcepub fn downcast_mut<__T: Object>(&mut self) -> Option<&mut __T>
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§impl dyn Object
impl dyn Object
Sourcepub fn cast_to_trait<T: ?Sized + 'static>(&self) -> Option<&T>
pub 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.
This method is only for casting to &dyn Trait
;
see ObjectArcExt
for limitations.