Trait ts_rs::typelist::TypeList

source ·
pub trait TypeList: Copy + Clone {
    // Required methods
    fn contains<C: Sized + 'static>(self) -> bool;
    fn for_each(self, v: &mut impl TypeVisitor);

    // Provided methods
    fn push<T: TS + 'static + ?Sized>(self) -> impl TypeList { ... }
    fn extend(self, l: impl TypeList) -> impl TypeList { ... }
}
Expand description

A list containing types implementing TS + 'static + ?Sized.

To construct a TypeList, start with the empty list, which is the unit type (), and repeatedly call TypeList::push or TypeList::extend on it.

Example:

fn primitives() -> impl TypeList {
    let signed = ().push::<i8>().push::<i16>().push::<i32>().push::<i64>();
    let unsigned = ().push::<u8>().push::<u16>().push::<u32>().push::<u64>();
    ().push::<char>()
      .push::<bool>()
      .extend(signed)
      .extend(unsigned)
}

The only way to get access to the types contained in a TypeList is to iterate over it by creating a visitor implementing TypeVisitor and calling TypeList::for_each.

Under the hood, TypeList is recursively defined as follows:

Required Methods§

source

fn contains<C: Sized + 'static>(self) -> bool

source

fn for_each(self, v: &mut impl TypeVisitor)

Provided Methods§

source

fn push<T: TS + 'static + ?Sized>(self) -> impl TypeList

source

fn extend(self, l: impl TypeList) -> impl TypeList

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl TypeList for ()

source§

fn contains<C: Sized>(self) -> bool

source§

fn for_each(self, _: &mut impl TypeVisitor)

source§

impl<A, B> TypeList for (A, B)
where A: TypeList, B: TypeList,

source§

fn contains<C: Sized + 'static>(self) -> bool

source§

fn for_each(self, v: &mut impl TypeVisitor)

source§

impl<T> TypeList for (PhantomData<T>,)
where T: TS + 'static + ?Sized,

source§

fn contains<C: Sized + 'static>(self) -> bool

source§

fn for_each(self, v: &mut impl TypeVisitor)

Implementors§