Trait typescript_type_def::TypeDef[][src]

pub trait TypeDef: 'static {
    const INFO: TypeInfo;
}
Expand description

A Rust type that has a corresponding TypeScript type definition.

For a Rust type T, the TypeDef trait defines a TypeScript type which describes JavaScript value that are equivalents of Rust values of type T as encoded to JSON using serde_json. The types are one-to-one, so decoding from TypeScript to JSON to Rust also works.

You should use #[derive(TypeDef)] macro to implement this trait on your own types.

This trait is implemented for basic Rust types as follows:

Rust typeTypeScript type
boolboolean
Stringstring
strstring
numeric typesnumber1
()null
(A, B, C)[A, B, C]
[T; N][T, T, ..., T] (an N-tuple)
Option<T>T | null
Vec<T>T[]
[T]T[]
HashSet<T>T[]
BTreeSet<T>T[]
HashMap<K, V>Record<K, V>
BTreeMap<K, V>Record<K, V>
&'static TT
Box<T>T
Cow<'static, T>T
PhantomData<T>T

  1. Numeric types are emitted as named aliases converted to PascalCase (e.g. Usize, I32, F64, NonZeroI8, etc.). Since they are simple aliases they do not enforce anything in TypeScript about the Rust types’ numeric bounds, but serve to document their intended range. 

Associated Constants

A constant value describing the structure of this type.

This type information is used to emit a TypeScript type definition.

Implementations on Foreign Types

Implementors