Trait TypeMarker

pub unsafe trait TypeMarker: Sized + 'static {
    type Owned;

    // Required methods
    fn inline_align(context: Context) -> usize;
    fn inline_size(context: Context) -> usize;

    // Provided methods
    fn encode_is_copy() -> bool { ... }
    fn decode_is_copy() -> bool { ... }
}
Expand description

A FIDL type marker.

This trait is only used for compile time dispatch. For example, we can parameterize code on T: TypeMarker, but we would never write value: T. In fact, T is often a zero-sized struct. From the user’s perspective, T::Owned is the FIDL type’s “Rust type”. For example, for the FIDL type string:10, T is BoundedString<10> and T::Owned is String.

For primitive types and user-defined types, Self is actually the same as Self::Owned. For all others (strings, arrays, vectors, handles, endpoints, optionals, error results), Self is a zero-sized struct that uses generics to represent FIDL type information such as the element type or constraints.

§Safety

  • Implementations of encode_is_copy must only return true if it is safe to transmute from *const Self::Owned to *const u8 and read inline_size bytes starting from that address.

  • Implementations of decode_is_copy must only return true if it is safe to transmute from *mut Self::Owned to *mut u8 and write inline_size bytes starting at that address.

Required Associated Types§

type Owned

The owned Rust type which this FIDL type decodes into.

Required Methods§

fn inline_align(context: Context) -> usize

Returns the minimum required alignment of the inline portion of the encoded object. It must be a (nonzero) power of two.

fn inline_size(context: Context) -> usize

Returns the size of the inline portion of the encoded object, including padding for alignment. Must be a multiple of inline_align.

Provided Methods§

fn encode_is_copy() -> bool

Returns true if the memory layout of Self::Owned matches the FIDL wire format and encoding requires no validation. When true, we can optimize encoding arrays and vectors of Self::Owned to a single memcpy.

This can be true even when decode_is_copy is false. For example, bools require validation when decoding, but they do not require validation when encoding because Rust guarantees a bool is either 0x00 or 0x01.

fn decode_is_copy() -> bool

Returns true if the memory layout of Self::Owned matches the FIDL wire format and decoding requires no validation. When true, we can optimize decoding arrays and vectors of Self::Owned to a single memcpy.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl TypeMarker for bool

§

impl TypeMarker for f32

§

impl TypeMarker for f64

§

impl TypeMarker for i8

§

impl TypeMarker for i16

§

impl TypeMarker for i32

§

impl TypeMarker for i64

§

impl TypeMarker for u8

§

impl TypeMarker for u16

§

impl TypeMarker for u32

§

impl TypeMarker for u64

Implementors§

§

impl TypeMarker for FrameworkErr

§

impl TypeMarker for ObjectType

§

impl TypeMarker for Rights

§

impl TypeMarker for WireMetadata

§

impl TypeMarker for Ambiguous1

§

impl TypeMarker for Ambiguous2

§

impl TypeMarker for EmptyPayload

§

type Owned = ()

§

impl TypeMarker for EmptyStruct

§

type Owned = ()

§

impl TypeMarker for EpitaphBody

§

impl TypeMarker for TransactionHeader

§

impl<H, T> TypeMarker for GenericMessageType<H, T>

§

impl<T> TypeMarker for Boxed<T>
where T: TypeMarker,

§

type Owned = Option<Box<<T as TypeMarker>::Owned>>

§

impl<T> TypeMarker for FlexibleType<T>
where T: TypeMarker,

§

type Owned = Flexible<<T as TypeMarker>::Owned>

§

impl<T> TypeMarker for Optional<T>
where T: TypeMarker,

§

type Owned = Option<<T as TypeMarker>::Owned>

§

impl<T> TypeMarker for OptionalUnion<T>
where T: TypeMarker,

§

type Owned = Option<Box<<T as TypeMarker>::Owned>>

§

impl<T, E> TypeMarker for FlexibleResultType<T, E>
where T: TypeMarker, E: TypeMarker,

§

type Owned = FlexibleResult<<T as TypeMarker>::Owned, <E as TypeMarker>::Owned>

§

impl<T, E> TypeMarker for ResultType<T, E>
where T: TypeMarker, E: TypeMarker,

§

type Owned = Result<<T as TypeMarker>::Owned, <E as TypeMarker>::Owned>

§

impl<T, U> TypeMarker for Instant<T, U>
where T: Timeline + 'static, U: 'static,

§

type Owned = Instant<T, U>

§

impl<T, const N: usize> TypeMarker for Array<T, N>
where T: TypeMarker,

§

type Owned = [<T as TypeMarker>::Owned; N]

§

impl<T, const N: usize> TypeMarker for Vector<T, N>
where T: TypeMarker,

§

type Owned = Vec<<T as TypeMarker>::Owned>

§

impl<T, const OBJECT_TYPE: u32, const RIGHTS: u32> TypeMarker for HandleType<T, OBJECT_TYPE, RIGHTS>
where T: 'static + EncodableAsHandle,

§

type Owned = T

§

impl<const N: usize> TypeMarker for BoundedString<N>