Meta

Struct Meta 

Source
pub struct Meta { /* private fields */ }
Expand description

Stores fat pointer metadata in a type-erased way.

Used internally by MultiAny to safely downcast to concrete types or trait objects.

§Fields

  • meta_raw: Raw metadata pointer stored as usize.
  • data_id: TypeId of the original data type.
  • meta_id: TypeId of the metadata type.

§Safety

  • meta_raw must have been created from a DynMetadata<T> or ().
  • data_id and meta_id must match the data and metadata types exactly.

Implementations§

Source§

impl Meta

Source

pub fn try_from<Data, RequestedType>( data: &Data, requested_type_id: TypeId, cast_fn: fn(&Data) -> &RequestedType, ) -> Option<Meta>
where Data: 'static, RequestedType: Pointee + ?Sized + 'static, RequestedType::Metadata: TypedMetadata,

Attempts to construct Meta for a requested type.

§Parameters
  • data: Reference to the concrete data.
  • requested_type_id: TypeId of the requested type.
  • cast_fn: Function to cast &Data to &RequestedType.
§Returns
  • Some(Meta) if requested_type_id matches RequestedType.
  • None otherwise.
§Type Parameters
  • Data: Concrete type stored in the MultiAny.
  • RequestedType: Type to attempt downcasting to.
Source

pub fn into_metadata<Data, RequestedType>(self) -> RequestedType::Metadata
where Data: 'static, RequestedType: Pointee + ?Sized + 'static, RequestedType::Metadata: TypedMetadata,

Converts this Meta into the concrete metadata type for a requested type.

§Type Parameters
  • Data: The concrete type stored in the MultiAny.
  • RequestedType: The type whose metadata you want to reconstruct.
§Returns

The metadata of type RequestedType::Metadata.

Auto Trait Implementations§

§

impl Freeze for Meta

§

impl RefUnwindSafe for Meta

§

impl Send for Meta

§

impl Sync for Meta

§

impl Unpin for Meta

§

impl UnwindSafe for Meta

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> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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.