ConstTypeName

Trait ConstTypeName 

Source
pub trait ConstTypeName {
    const RAW_SLICE: &[&str];
    const TYPE_NAME_FSTR: fstr<CONST_TYPENAME_LEN> = _;
}
Expand description

A trait for providing a const fixed string for the type name, used to avoid heap when need to format the type name.

Useful for types with generic parameters. the size of the type name is limited by CONST_TYPENAME_LEN, which can be configured by feature flags len128, len64 and len256, the default is len128.

But note that implementing this trait for a lot of types will make your binary size larger, and slow down your compile time.

§Example

use fixed_type_id::prelude::*;
pub struct A<T> {
    pub t: T,
}

impl<T: FixedTypeId> FixedTypeId for A<T> {
    const TYPE_NAME: &'static str = fstr_to_str(&Self::TYPE_NAME_FSTR);
}

impl<T: FixedTypeId> ConstTypeName for A<T> {
    const RAW_SLICE: &[&str] = &["A", "<", T::TYPE_NAME, ">"];
}

assert_eq!(<A<u8> as FixedTypeId>::TYPE_NAME, "A<u8>");

Required Associated Constants§

Source

const RAW_SLICE: &[&str]

A raw slice for the type name, used to create a fixed fstr.

It’s the only const you should defined for your struct.

Provided Associated Constants§

Source

const TYPE_NAME_FSTR: fstr<CONST_TYPENAME_LEN> = _

A fixed string for the type name, used to avoid heap when need to format the type name.

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<K: FixedTypeId, V: FixedTypeId> ConstTypeName for BTreeMap<K, V>

Source§

impl<K: FixedTypeId, V: FixedTypeId, S> ConstTypeName for HashMap<K, V, S>

Source§

impl<R: FixedTypeId> ConstTypeName for fn() -> R

Source§

const RAW_SLICE: &'static [&'static str]

Source§

impl<T1: FixedTypeId, T2: FixedTypeId> ConstTypeName for (T1, T2)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId> ConstTypeName for (T1, T2, T3)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId> ConstTypeName for (T1, T2, T3, T4)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId, T7: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6, T7)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId, T7: FixedTypeId, T8: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6, T7, T8)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId, T7: FixedTypeId, T8: FixedTypeId, T9: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6, T7, T8, T9)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId, T7: FixedTypeId, T8: FixedTypeId, T9: FixedTypeId, T10: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId, T7: FixedTypeId, T8: FixedTypeId, T9: FixedTypeId, T10: FixedTypeId, T11: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId, T7: FixedTypeId, T8: FixedTypeId, T9: FixedTypeId, T10: FixedTypeId, T11: FixedTypeId, T12: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId, T7: FixedTypeId, T8: FixedTypeId, T9: FixedTypeId, T10: FixedTypeId, T11: FixedTypeId, T12: FixedTypeId, T13: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId, T7: FixedTypeId, T8: FixedTypeId, T9: FixedTypeId, T10: FixedTypeId, T11: FixedTypeId, T12: FixedTypeId, T13: FixedTypeId, T14: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId, T7: FixedTypeId, T8: FixedTypeId, T9: FixedTypeId, T10: FixedTypeId, T11: FixedTypeId, T12: FixedTypeId, T13: FixedTypeId, T14: FixedTypeId, T15: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)

Source§

impl<T1: FixedTypeId, T2: FixedTypeId, T3: FixedTypeId, T4: FixedTypeId, T5: FixedTypeId, T6: FixedTypeId, T7: FixedTypeId, T8: FixedTypeId, T9: FixedTypeId, T10: FixedTypeId, T11: FixedTypeId, T12: FixedTypeId, T13: FixedTypeId, T14: FixedTypeId, T15: FixedTypeId, T16: FixedTypeId> ConstTypeName for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)

Source§

impl<T: ZeroablePrimitive + FixedTypeId> ConstTypeName for NonZero<T>

Source§

impl<T: FixedTypeId + ?Sized> ConstTypeName for &T

Source§

const RAW_SLICE: &'static [&'static str]

Source§

impl<T: FixedTypeId + ?Sized> ConstTypeName for &mut T

Source§

const RAW_SLICE: &'static [&'static str]

Source§

impl<T: FixedTypeId + ?Sized> ConstTypeName for Box<T>

Source§

impl<T: FixedTypeId> ConstTypeName for &[T]

Source§

const RAW_SLICE: &'static [&'static str]

Source§

impl<T: FixedTypeId> ConstTypeName for &mut [T]

Source§

const RAW_SLICE: &'static [&'static str]

Source§

impl<T: FixedTypeId> ConstTypeName for Option<T>

Source§

impl<T: FixedTypeId> ConstTypeName for (T,)

Source§

impl<T: FixedTypeId> ConstTypeName for VecDeque<T>

Source§

impl<T: FixedTypeId> ConstTypeName for Vec<T>

Source§

impl<T: FixedTypeId> ConstTypeName for PhantomData<T>

Source§

impl<T: FixedTypeId> ConstTypeName for Range<T>

Source§

impl<T: FixedTypeId> ConstTypeName for RangeFrom<T>

Source§

impl<T: FixedTypeId> ConstTypeName for RangeTo<T>

Source§

impl<T: FixedTypeId> ConstTypeName for RangeToInclusive<T>

Source§

impl<T: FixedTypeId, E: FixedTypeId> ConstTypeName for Result<T, E>

Source§

impl<T: FixedTypeId, R: FixedTypeId> ConstTypeName for fn(T) -> R

Source§

const RAW_SLICE: &'static [&'static str]

Source§

impl<T: FixedTypeId, const N: usize> ConstTypeName for [T; N]
where [T; N]:,

Only valid for N <= 32

Implementors§