Struct abi_stable::prefix_type::WithMetadata_
source · #[repr(C)]pub struct WithMetadata_<T, P> {
pub value: AlignToUsize<T>,
/* private fields */
}
Expand description
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,
};
const WITH_META: &WithMetadata<Module> = &WithMetadata::new(
Module {
first: RSome(66),
second: RStr::from_str("lore"),
third: 333,
},
);
const MOD: Module_Ref = Module_Ref(WITH_META.static_as_prefix());
assert_eq!(MOD.first(), RSome(66));
assert_eq!(MOD.second().as_str(), "lore");
Fields§
§value: AlignToUsize<T>
The wrapped value.
Implementations§
source§impl<T, P> WithMetadata_<T, P>
impl<T, P> WithMetadata_<T, P>
sourcepub const fn new(value: T) -> Selfwhere
T: PrefixTypeTrait<PrefixFields = P>,
pub const fn new(value: T) -> Selfwhere
T: PrefixTypeTrait<PrefixFields = P>,
Constructs this with WithMetadata::new(value)
sourcepub const fn field_accessibility(&self) -> FieldAccessibility
pub const fn field_accessibility(&self) -> FieldAccessibility
A bit array that describes the accessibility of each field in T
.
sourcepub const fn type_layout(&self) -> &'static PTStructLayout
pub const fn type_layout(&self) -> &'static PTStructLayout
The basic layout of the prefix type, for error messages.
sourcepub const unsafe fn raw_as_prefix(this: *const Self) -> PrefixRef<P>
pub const unsafe fn raw_as_prefix(this: *const Self) -> PrefixRef<P>
Constructs a PrefixRef
from this
.
§Safety
You must enture that this WithMetadata
lives for the entire program’s lifetime.
sourcepub const unsafe fn as_prefix(&self) -> PrefixRef<P>
pub const unsafe fn as_prefix(&self) -> PrefixRef<P>
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
.
sourcepub const fn static_as_prefix(&'static self) -> PrefixRef<P>
pub const fn static_as_prefix(&'static self) -> PrefixRef<P>
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(
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> Freeze for WithMetadata_<T, P>where
T: Freeze,
impl<T, P> RefUnwindSafe for WithMetadata_<T, P>where
T: RefUnwindSafe,
P: RefUnwindSafe,
impl<T, P> Send for WithMetadata_<T, P>
impl<T, P> Sync for WithMetadata_<T, P>
impl<T, P> Unpin for WithMetadata_<T, P>
impl<T, P> UnwindSafe for WithMetadata_<T, P>where
T: UnwindSafe,
P: UnwindSafe,
Blanket Implementations§
source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset
. Read moresource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset
. Read moresource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset
. Read moresource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset
. Read moresource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moresource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moresource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read moresource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
.source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more