pub unsafe trait MarkerType: Copy + Sized {
    const MTVAL: Self = _;

    fn markertype_ref<'a>() -> &'a Self
    where
        Self: 'a
, { ... } fn markertype_val() -> Self { ... } }
Available on crate feature 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

The value of Self.

Provided Methods

Constructs a reference to Self.

Constructs Self,this is possible because Self implements MarkerType.

Implementations on Foreign Types

Implementors