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 readinline_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 writeinline_size
bytes starting at that address.
Required Associated Types§
Required Methods§
Sourcefn inline_align(context: Context) -> usize
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.
Sourcefn inline_size(context: Context) -> usize
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§
Sourcefn encode_is_copy() -> bool
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.
Sourcefn decode_is_copy() -> bool
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.