[−][src]Trait const_format::marker_traits::FormatMarker
Marker trait for types that implement the const formatting methods.
Implementors
Types that implement this trait are also expected to implement at least one of these inherent methods:
// use const_format::{Error, Format}; const fn const_debug_fmt(&self, &mut Formatter<'_>) -> Result<(), Error> const fn const_display_fmt(&self, &mut Formatter<'_>) -> Result<(), Error>
Coercions
The Kind
and This
associated types
are used in the IsAFormatMarker
marker type
to automatically wrap types in PWrapper
if they're from the standard library,
otherwise leaving them unwrapped.
Examples
Display formatting
This example demonstrates how you can implement display formatting,
without using the impl_fmt
macro.
#![feature(const_mut_refs)] use const_format::{ marker_traits::{FormatMarker, IsNotStdKind}, Error, Formatter, StrWriter, formatc, writec, }; use std::cmp::Ordering; struct Compared(u32, Ordering, u32); // This is what the `impl_fmt` macro implements implicitly for all non-std types impl FormatMarker for Compared { type Kind = IsNotStdKind; type This = Self; } impl Compared { pub const fn const_display_fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { let op = match self.1 { Ordering::Less => "<", Ordering::Equal => "==", Ordering::Greater => ">", }; writec!(f, "{} {} {}", self.0, op, self.2) } } const S_0: &str = formatc!("{}", Compared(0, Ordering::Less, 1)); const S_1: &str = formatc!("{}", Compared(1, Ordering::Equal, 1)); const S_2: &str = formatc!("{}", Compared(2, Ordering::Greater, 1)); assert_eq!(S_0, "0 < 1"); assert_eq!(S_1, "1 == 1"); assert_eq!(S_2, "2 > 1");
Debug formatting
These are examples of implementing debug formatting using the impl_fmt
macro for:
Associated Types
type Kind
What kind of type this is, this can be one of:
-
IsArrayKind
: For slices, and arrays. -
IsStdKind
: Any other standard library type. -
IsNotStdKind
: Any type that is not from the standard library.
type This: ?Sized
The type after dereferencing,
implemented as type This = Self;
for all non-reference types
Implementations on Foreign Types
impl FormatMarker for i8
[src]
impl FormatMarker for u8
[src]
impl FormatMarker for i16
[src]
impl FormatMarker for u16
[src]
impl FormatMarker for i32
[src]
impl FormatMarker for u32
[src]
impl FormatMarker for i64
[src]
impl FormatMarker for u64
[src]
impl FormatMarker for i128
[src]
impl FormatMarker for u128
[src]
impl FormatMarker for isize
[src]
impl FormatMarker for usize
[src]
impl FormatMarker for bool
[src]
impl FormatMarker for str
[src]
impl<T> FormatMarker for [T; 0]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 1]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 2]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 3]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 4]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 5]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 6]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 7]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 8]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 9]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 10]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 11]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 12]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 13]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 14]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 15]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 16]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 17]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 18]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 19]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 20]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 21]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 22]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 23]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 24]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 25]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 26]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 27]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 28]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 29]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 30]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 31]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 32]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 33]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 34]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 35]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 36]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 37]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 38]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 39]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 40]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 41]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 42]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 43]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 44]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 45]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 46]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 47]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 48]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 49]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 50]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 51]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 52]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 53]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 54]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 55]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 56]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 57]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 58]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 59]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 60]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 61]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 62]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T; 63]
[src]
type Kind = IsArrayKind<T>
type This = Self
impl<T> FormatMarker for [T]
[src]
type Kind = IsArrayKind<T>
type This = [T]
impl<T: ?Sized, '_> FormatMarker for &'_ T where
T: FormatMarker,
[src]
T: FormatMarker,
impl<T: ?Sized, '_> FormatMarker for &'_ mut T where
T: FormatMarker,
[src]
T: FormatMarker,