Trait fidl::encoding::TypeMarker

source ·
pub unsafe trait TypeMarker: 'static + Sized {
    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§

source

type Owned

The owned Rust type which this FIDL type decodes into.

Required Methods§

source

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.

source

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§

source

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.

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl TypeMarker for bool

source§

impl TypeMarker for f32

source§

impl TypeMarker for f64

source§

impl TypeMarker for i8

source§

impl TypeMarker for i16

source§

impl TypeMarker for i32

source§

impl TypeMarker for i64

source§

impl TypeMarker for u8

source§

impl TypeMarker for u16

source§

impl TypeMarker for u32

source§

impl TypeMarker for u64

Implementors§

source§

impl TypeMarker for FrameworkErr

source§

impl TypeMarker for ObjectType

source§

impl TypeMarker for Rights

source§

impl TypeMarker for WireMetadata

source§

impl TypeMarker for Ambiguous1

source§

impl TypeMarker for Ambiguous2

source§

impl TypeMarker for EmptyPayload

§

type Owned = ()

source§

impl TypeMarker for EmptyStruct

§

type Owned = ()

source§

impl TypeMarker for EpitaphBody

source§

impl TypeMarker for TransactionHeader

source§

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

source§

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

§

type Owned = T

source§

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

§

type Owned = Instant<T, U>

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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

§

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

source§

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