Trait core_extensions::MarkerType
source · [−]pub unsafe trait MarkerType: Copy + Sized {
const MTVAL: Self = _;
fn markertype_ref<'a>() -> &'a Self
where
Self: 'a,
{ ... }
fn markertype_val() -> Self { ... }
}
marker_type
only.Expand description
Represents a zero-sized marker type .
Types implementing this trait are zero-sized and can safely be stored in any
#[repr(C)]
type without changing their layout.
Safety
Implementors of this trait must ensure:
-
That the type is zero-sized,
-
That it has an alignment of 1.
-
That the type is trivially constructible, eg: by implementing
Default
.
The easiest way to enforce the requirements of being zero-sized and
having an alignment of 1 is to have structs composed entirely of MarkerType fields
(ie: PhantomData
).
Built-in impls
This trait is not implemented for arrays because it’s not yet clear
what the behavior of #[repr(C)]
types will be with zero-sized arrays.
The “repr(C) is unsound on MSVC targets” issue
could possibly require zero-length arrays(or #[repr(C)]
structs)
in #[repr(C)]
types not being zero sized on MSVC.
Provided Associated Constants
Provided Methods
sourcefn markertype_ref<'a>() -> &'a Self where
Self: 'a,
fn markertype_ref<'a>() -> &'a Self where
Self: 'a,
Constructs a reference to Self.
sourcefn markertype_val() -> Self
fn markertype_val() -> Self
Constructs Self,this is possible because Self implements MarkerType.
Implementations on Foreign Types
impl<T: ?Sized> MarkerType for PhantomData<T>
impl<T> MarkerType for ManuallyDrop<T> where
T: MarkerType,
Implementors
impl MarkerType for False
type_level_bool
only.impl MarkerType for True
type_level_bool
only.