fixed_type_id

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::{ConstTypeName, FixedTypeId, fstr_to_str};
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, V> ConstTypeName for BTreeMap<K, V>
where K: FixedTypeId, V: FixedTypeId,

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

impl<T> ConstTypeName for NonZero<T>

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

Source§

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

Source§

const RAW_SLICE: &[&str] = _

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§

const RAW_SLICE: &[&str] = _

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 (T,)

Source§

const RAW_SLICE: &[&str] = _

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

Source§

const RAW_SLICE: &[&str] = _

Implementors§