fidl::encoding

Trait 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.

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§

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

Source§

impl TypeMarker for EmptyStruct

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>

Source§

type Owned = T

Source§

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

Source§

type Owned = Instant<T, U>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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