pub struct ObjectRef<T: 'static>(/* private fields */);
Expand description
When the concrete type of an object is known statically, we can provide an ObjectRef wrapper around the ObjectId in order to make downcasting simpler.
This is primarily useful when vending self references to MessageReceviers.
Implementations§
Source§impl<T> ObjectRef<T>
impl<T> ObjectRef<T>
pub fn from_id(id: ObjectId) -> Self
pub fn id(&self) -> ObjectId
Sourcepub fn get<'a>(&self, client: &'a Client) -> Result<&'a T, ObjectLookupError>
pub fn get<'a>(&self, client: &'a Client) -> Result<&'a T, ObjectLookupError>
Provides an immutable reference to an object, downcasted to |T|.
Sourcepub fn try_get<'a>(&self, client: &'a Client) -> Option<&'a T>
pub fn try_get<'a>(&self, client: &'a Client) -> Option<&'a T>
Provides an immutable reference to an object, downcasted to |T|, if available.
Sourcepub fn get_mut<'a>(
&self,
client: &'a mut Client,
) -> Result<&'a mut T, ObjectLookupError>
pub fn get_mut<'a>( &self, client: &'a mut Client, ) -> Result<&'a mut T, ObjectLookupError>
Provides a mutable reference to an object, downcasted to |T|.
Sourcepub fn try_get_mut<'a>(&self, client: &'a mut Client) -> Option<&'a mut T>
pub fn try_get_mut<'a>(&self, client: &'a mut Client) -> Option<&'a mut T>
Provides a mutable reference to an object, downcasted to |T|, if available.
Sourcepub fn is_valid(&self, client: &mut Client) -> bool
pub fn is_valid(&self, client: &mut Client) -> bool
Returns true
iff the underlying object is still valid.
Here ‘valid’ means that the object_id exists and refers to an object
of type T
. This method will still return true
if the associated
object_id has been deleted and recreated with the same type T. If this is not desirable then the caller must track instance with some state embedded into
T`.
This can be useful to verify prior to sending events using the associated object_id but the host object itself is not required.
Trait Implementations§
impl<T: 'static> Copy for ObjectRef<T>
impl<T> Eq for ObjectRef<T>
Auto Trait Implementations§
impl<T> Freeze for ObjectRef<T>
impl<T> RefUnwindSafe for ObjectRef<T>where
T: RefUnwindSafe,
impl<T> Send for ObjectRef<T>where
T: Send,
impl<T> Sync for ObjectRef<T>where
T: Sync,
impl<T> Unpin for ObjectRef<T>where
T: Unpin,
impl<T> UnwindSafe for ObjectRef<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)