Typeable

Trait Typeable 

Source
pub trait Typeable {
    // Required method
    fn type_ident() -> TypeId;
}
Expand description

A trait that specifies unique identifiers for types in a deterministic way that can be shared on multiple machines over the network.

Requirements:

  • 1-1 mapping between a (fully instantiated) type and its identifier, assuming no hash collisions.
  • A type identifier should be deterministic so that it is the same on different machines (and compilation configurations).
  • Changes to a type’s semantics should result in a different type identifier. By default, type identifiers are derived from type declarations, so changes to semantics like function implementations should cause the type identifier to change. In practice, this may require tag updates (ex. changing a tag from “v1” to “v2” when a type’s implementation changes).

The following is the grammar of how the type is hashed to create its identifier. Primitive types may have custom encodings that do not match this grammar.

typeable := type_name type_arg_count tag type_body

type_name := string type_arg_count := u8 type_body := // Struct ‘0’ fields // Enum | ‘1’ variant_count variant*

fields := // Named fields {} ‘0’ field_count field // Unnamed fields () | ‘1’ field_count type_ident*

field := field_name type_ident field_name := string

tag := string | _

variant := variant_name fields

field_count := u8 char_count := u8 variant_count := u8

string := char_count alphanumeric alphanumeric := [a-zA-Z0-9_]*

type_ident := [u8; 32]

Required Methods§

Source

fn type_ident() -> TypeId

A unique identifier for a given type.

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 Typeable for bool

Source§

impl Typeable for char

Source§

impl Typeable for f32

Source§

impl Typeable for f64

Source§

impl Typeable for i8

Source§

impl Typeable for i16

Source§

impl Typeable for i32

Source§

impl Typeable for i64

Source§

impl Typeable for i128

Source§

impl Typeable for u8

Source§

impl Typeable for u16

Source§

impl Typeable for u32

Source§

impl Typeable for u64

Source§

impl Typeable for u128

Source§

impl Typeable for String

Source§

impl<T: Typeable> Typeable for Option<T>

Source§

impl<T: Typeable> Typeable for Vec<T>

Source§

impl<T: Typeable, const N: usize> Typeable for [T; N]

Implementors§