Ref

Struct Ref 

Source
pub struct Ref<'a, Trait: ?Sized + DynTrait> { /* private fields */ }
Expand description

A shared reference to a tinydyn trait object.

Ref<dyn Trait> can call the &self methods of Trait through its Deref impl. It can also be freely cloned and copied like a &dyn Trait.

Prefer passing this around rather than calling deref and passing around that reference

  • that would create a double pointer.

Implementations§

Source§

impl<'a, Trait: ?Sized + DynTrait> Ref<'a, Trait>

Source

pub fn new<U>(r: &'a U) -> Self
where <<Trait as DynTrait>::Plain as PlainDyn>::LocalNewtype<U>: Implements<Trait>,

Upcasts this &U into a Ref<dyn Trait> so long as U: Trait.

This builds a tinydyn vtable and references it in the returned Ref.

Source§

impl<'a, Trait: ?Sized + DynTrait + Send + 'a> Ref<'a, Trait>

Source

pub fn remove_send(self) -> Ref<'a, Trait::RemoveSend>

Removes the Send bound from Trait, if any.

Source§

impl<'a, Trait: ?Sized + DynTrait + Sync + 'a> Ref<'a, Trait>

Source

pub fn remove_sync(self) -> Ref<'a, Trait::RemoveSync>

Removes the Sync bound from Trait, if any.

Trait Implementations§

Source§

impl<'a, Trait: ?Sized + DynTrait + 'a> Clone for Ref<'a, Trait>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, Trait: ?Sized + DynTrait + 'a> Deref for Ref<'a, Trait>

Source§

fn deref(&self) -> &Self::Target

It’s not recommended to hold onto the result of this deref, as it creates a double reference.

Source§

type Target = DynTarget<Trait>

The resulting type after dereferencing.
Source§

impl<'a, Trait: ?Sized + DynTrait> From<RefMut<'a, Trait>> for Ref<'a, Trait>

Source§

fn from(value: RefMut<'a, Trait>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Trait: ?Sized + DynTrait + 'a> Copy for Ref<'a, Trait>

Source§

impl<'a, Trait> Send for Ref<'a, Trait>
where Trait: ?Sized + DynTrait, &'a Trait: Send,

Source§

impl<'a, Trait> Sync for Ref<'a, Trait>
where Trait: ?Sized + DynTrait, &'a Trait: Sync,

Auto Trait Implementations§

§

impl<'a, Trait> Freeze for Ref<'a, Trait>
where <<Trait as DynTrait>::Plain as PlainDyn>::Metadata: Freeze, Trait: ?Sized,

§

impl<'a, Trait> RefUnwindSafe for Ref<'a, Trait>
where <<Trait as DynTrait>::Plain as PlainDyn>::Metadata: RefUnwindSafe, Trait: RefUnwindSafe + ?Sized,

§

impl<'a, Trait> Unpin for Ref<'a, Trait>
where <<Trait as DynTrait>::Plain as PlainDyn>::Metadata: Unpin, Trait: ?Sized,

§

impl<'a, Trait> UnwindSafe for Ref<'a, Trait>
where <<Trait as DynTrait>::Plain as PlainDyn>::Metadata: UnwindSafe, Trait: RefUnwindSafe + ?Sized,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.