Skip to main content

EnvelopeMut

Struct EnvelopeMut 

Source
pub struct EnvelopeMut<'a> { /* private fields */ }
Expand description

A mutably borrowed reflected value with read + write capability access.

Created by reflect_mut! or Envelope::as_mut. Analogous to &mut [T]. Provides mutable access to capabilities without consuming the original value.

§Example

let mut value = Counter { count: 42 };
let mut envelope_mut = reflect_mut!(&mut value);
envelope_mut.get_mut::<ResettableCap>().unwrap().reset();
assert_eq!(value.count, 0);

Implementations§

Source§

impl<'a> EnvelopeMut<'a>

Source

pub fn from_parts(data: &'a mut dyn Any, caps: CapabilityMap) -> Self

Source

pub fn caps(&self) -> &CapabilityMap

Get a shared reference to the capability map.

Source

pub fn as_ref(&self) -> EnvelopeRef<'_>

Downgrade to a read-only EnvelopeRef.

Source

pub fn get<C: Capability>(&self) -> Option<&C::Handle>

Get a shared reference to the capability’s trait object.

Returns None if the wrapped type doesn’t implement the capability’s trait bound.

Source

pub fn get_mut<C: Capability>(&mut self) -> Option<&mut C::Handle>

Get a mutable reference to the capability’s trait object.

Returns None if the wrapped type doesn’t implement the capability’s trait bound.

Source

pub fn has<C: Capability>(&self) -> bool

Check whether this envelope’s value has a given capability.

Source

pub fn data<T: 'static>(&self) -> Option<&T>

Get a shared reference to the underlying concrete type.

Returns None if T doesn’t match the actual stored type.

Source

pub fn data_mut<T: 'static>(&mut self) -> Option<&mut T>

Get a mutable reference to the underlying concrete type.

Returns None if T doesn’t match the actual stored type.

Source

pub fn capability_count(&self) -> usize

The number of capabilities detected on this value.

Auto Trait Implementations§

§

impl<'a> Freeze for EnvelopeMut<'a>

§

impl<'a> !RefUnwindSafe for EnvelopeMut<'a>

§

impl<'a> !Send for EnvelopeMut<'a>

§

impl<'a> !Sync for EnvelopeMut<'a>

§

impl<'a> Unpin for EnvelopeMut<'a>

§

impl<'a> UnsafeUnpin for EnvelopeMut<'a>

§

impl<'a> !UnwindSafe for EnvelopeMut<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.