[−][src]Struct abi_stable::prefix_type::WithMetadata_
Wraps a type along with its prefix-type-related metadata, so that it can be converted to its prefix.
Example
This example demonstrates how you can construct a WithMetadata
and
convert it to a prefix type pointer (Module_Ref
in this case).
You can look at the PrefixRef
docs for
a more detailed example.
use abi_stable::{ for_examples::{Module, Module_Ref}, prefix_type::{PrefixRef, PrefixTypeTrait, WithMetadata}, std_types::{RSome, RStr}, staticref, }; // The `staticref` invocation here declares a `StaticRef<WithMetadata<Module>>` constant. staticref!{const WITH_META: WithMetadata<Module> = WithMetadata::new( PrefixTypeTrait::METADATA, Module { first: RSome(66), second: RStr::from_str("lore"), third: 333, }, )} const MOD: Module_Ref = Module_Ref(WITH_META.as_prefix()); assert_eq!(MOD.first(), RSome(66)); assert_eq!(MOD.second().as_str(), "lore");
Fields
metadata: PrefixMetadata<T, P>
value: T
The wrapped value.
Implementations
impl<T, P> WithMetadata_<T, P>
[src]
pub const fn new(metadata: PrefixMetadata<T, P>, value: T) -> Self
[src]
Constructs this with WithMetadata::new(PrefixTypeTrait::METADATA, value)
This takes in the metadata: PrefixMetadata<T>
parameter as a
workaround for const fn
not allowing trait bounds,
which in this case is PrefixTypeTrait
.
pub const unsafe fn raw_as_prefix(this: *const Self) -> PrefixRef<P>
[src]
Constructs a PrefixRef
from this
.
Safety
You must enture that this WithMetadata
lives for the entire program's lifetime.
pub const unsafe fn as_prefix(&self) -> PrefixRef<P>
[src]
Constructs a PrefixRef
from self
.
Safety
You must ensure that self
lives for the entire program's lifetime.
Alternative
For a safe equivalent of this, you can use StaticRef::as_prefix
.
pub const fn static_as_prefix(&'static self) -> PrefixRef<P>
[src]
Constructs a PrefixRef
from self
.
Example
use abi_stable::{ for_examples::{Module, Module_Ref}, prefix_type::{PrefixRef, PrefixTypeTrait, WithMetadata}, std_types::{RSome, RStr}, }; const WITH_META: &WithMetadata<Module> = &WithMetadata::new( PrefixTypeTrait::METADATA, Module { first: RSome(13), second: RStr::from_str("foo"), third: 100, }, ); const MOD: Module_Ref = Module_Ref(WITH_META.static_as_prefix()); assert_eq!(MOD.first(), RSome(13)); assert_eq!(MOD.second().as_str(), "foo");
Auto Trait Implementations
impl<T, P> RefUnwindSafe for WithMetadata_<T, P> where
P: RefUnwindSafe,
T: RefUnwindSafe,
P: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, P> Send for WithMetadata_<T, P> where
P: Send,
T: Send,
P: Send,
T: Send,
impl<T, P> Sync for WithMetadata_<T, P> where
P: Sync,
T: Sync,
P: Sync,
T: Sync,
impl<T, P> Unpin for WithMetadata_<T, P> where
P: Unpin,
T: Unpin,
P: Unpin,
T: Unpin,
impl<T, P> UnwindSafe for WithMetadata_<T, P> where
P: UnwindSafe,
T: UnwindSafe,
P: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> GetWithMetadata for T
[src]
type ForSelf = WithMetadata_<T, T>
This is always WithMetadata_<Self, Self>
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SelfOps for T where
T: ?Sized,
[src]
T: ?Sized,
pub const T: PhantomData<fn() -> Self>
[src]
pub const T_D: PhantomData<Self>
[src]
pub fn assert_ty(self, _other: PhantomData<fn() -> Self>) -> Self
[src]
pub fn assert_ty_ref(&self, _other: PhantomData<fn() -> Self>) -> &Self
[src]
pub fn assert_ty_mut(&mut self, _other: PhantomData<fn() -> Self>) -> &mut Self
[src]
pub fn ty_(&self) -> PhantomData<fn() -> Self>
[src]
pub fn ty_d(&self) -> PhantomData<Self>
[src]
pub fn ty_inv(&self) -> PhantomData<fn(Self) -> Self>
[src]
pub fn ty_inv_ref(&self) -> PhantomData<Cell<&Self>>
[src]
pub fn eq_id(&self, other: &Self) -> bool
[src]
pub fn piped<F, U>(self, f: F) -> U where
F: FnOnce(Self) -> U,
[src]
F: FnOnce(Self) -> U,
pub fn piped_ref<'a, F, U>(&'a self, f: F) -> U where
F: FnOnce(&'a Self) -> U,
[src]
F: FnOnce(&'a Self) -> U,
pub fn piped_mut<'a, F, U>(&'a mut self, f: F) -> U where
F: FnOnce(&'a mut Self) -> U,
[src]
F: FnOnce(&'a mut Self) -> U,
pub fn mutated<F>(self, f: F) -> Self where
F: FnOnce(&mut Self),
[src]
F: FnOnce(&mut Self),
pub fn observe<F>(self, f: F) -> Self where
F: FnOnce(&Self),
[src]
F: FnOnce(&Self),
pub fn into_<T>(self, PhantomData<fn() -> T>) -> T where
Self: Into<T>,
[src]
Self: Into<T>,
pub fn as_ref_<T>(&self) -> &T where
Self: AsRef<T>,
T: ?Sized,
[src]
Self: AsRef<T>,
T: ?Sized,
pub fn as_mut_<T>(&mut self) -> &mut T where
Self: AsMut<T>,
T: ?Sized,
[src]
Self: AsMut<T>,
T: ?Sized,
pub fn drop_(self)
[src]
impl<This> TransmuteElement for This where
This: ?Sized,
[src]
This: ?Sized,
pub unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr where
Self: CanTransmuteElement<T>,
Self::Target: Sized,
[src]
Self: CanTransmuteElement<T>,
Self::Target: Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The error type returned when the conversion fails.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> TypeIdentity for T where
T: ?Sized,
[src]
T: ?Sized,
type Type = T
The same type as Self. Read more
pub fn into_type_val(self) -> Self::Type where
Self::Type: Sized,
[src]
Self::Type: Sized,
pub fn into_type_ref(&self) -> &Self::Type
[src]
pub fn into_type_mut(&mut self) -> &mut Self::Type
[src]
pub fn into_type_box(self: Box<Self, Global>) -> Box<Self::Type, Global>
[src]
pub fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>
[src]
pub fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>
[src]
pub fn from_type_val(this: Self::Type) -> Self where
Self::Type: Sized,
[src]
Self::Type: Sized,