pub struct Display<T>(pub T);Expand description
fmt::Display alternative for a few types
Unfortunately it’s not currently possible to implement this as a trait, at least not in a way that could be used in const contexts.
Instead, this is implemented as a generic type with only one method: write.
Doing it this way spares us from needing a differently named method for each integer (e.g write_usize, write_u8 and so on).
It’s just sc = Display(thing).write(sc); for all supported types, and the correct method gets picked automatically.
This only fails when the type isn’t known, which might happen with sc = Display(123).write(sc);.
In this case, you can disambiguate with Display(123u8), and if it’s not an integer literal, Display::<u8>(123) always works.
Additionally, having the same syntax for all “implementors” allows writing a very simple macro to simplify this.
(It would also be possible to write a macro like format!(), but that would be a proc-macro, and not very simple).
Tuple Fields§
§0: TImplementations§
Source§impl Display<u8>
impl Display<u8>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<u16>
impl Display<u16>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<u32>
impl Display<u32>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<u64>
impl Display<u64>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<u128>
impl Display<u128>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<usize>
impl Display<usize>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<i8>
impl Display<i8>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<i16>
impl Display<i16>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<i32>
impl Display<i32>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<i64>
impl Display<i64>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<i128>
impl Display<i128>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<isize>
impl Display<isize>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroI8>
impl Display<NonZeroI8>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroI16>
impl Display<NonZeroI16>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroI32>
impl Display<NonZeroI32>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroI64>
impl Display<NonZeroI64>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroI128>
impl Display<NonZeroI128>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroIsize>
impl Display<NonZeroIsize>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroU8>
impl Display<NonZeroU8>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroU16>
impl Display<NonZeroU16>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroU32>
impl Display<NonZeroU32>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroU64>
impl Display<NonZeroU64>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroU128>
impl Display<NonZeroU128>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<NonZeroUsize>
impl Display<NonZeroUsize>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the number into the StrConstrue (in base 10)
Source§impl Display<char>
impl Display<char>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the char into the StrConstrue
Source§impl Display<&str>
impl Display<&str>
Sourcepub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>
Writes the &str into the StrConstrue
Equivalent to StrConstrue::push_str.