[][src]Struct abi_stable::prefix_type::WithMetadata_

#[repr(C)]pub struct WithMetadata_<T, P> {
    pub metadata: PrefixMetadata<T, P>,
    pub value: T,
    // some fields omitted
}

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

impl<T, P> Send for WithMetadata_<T, P> where
    P: Send,
    T: Send

impl<T, P> Sync for WithMetadata_<T, P> where
    P: Sync,
    T: Sync

impl<T, P> Unpin for WithMetadata_<T, P> where
    P: Unpin,
    T: Unpin

impl<T, P> UnwindSafe for WithMetadata_<T, P> where
    P: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[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]

impl<T> SelfOps for T where
    T: ?Sized
[src]

impl<This> TransmuteElement for This where
    This: ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The error type returned when the conversion fails.

impl<T> TypeIdentity for T where
    T: ?Sized
[src]

type Type = T

The same type as Self. Read more