Display

Struct Display 

Source
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: T

Implementations§

Source§

impl Display<u8>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>

Writes the char into the StrConstrue

Source§

impl Display<&str>

Source

pub const fn write<const N: usize>(self, sc: StrConstrue<N>) -> StrConstrue<N>

Writes the &str into the StrConstrue

Equivalent to StrConstrue::push_str.

Auto Trait Implementations§

§

impl<T> Freeze for Display<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Display<T>
where T: RefUnwindSafe,

§

impl<T> Send for Display<T>
where T: Send,

§

impl<T> Sync for Display<T>
where T: Sync,

§

impl<T> Unpin for Display<T>
where T: Unpin,

§

impl<T> UnwindSafe for Display<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.