[][src]Trait const_format::marker_traits::FormatMarker

pub trait FormatMarker {
    type Kind;
    type This: ?Sized;
}
This is supported on crate feature fmt only.

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[src]

What kind of type this is, this can be one of:

type This: ?Sized[src]

The type after dereferencing, implemented as type This = Self; for all non-reference types

Loading content...

Implementations on Foreign Types

impl FormatMarker for Range<usize>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for RangeFrom<usize>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for RangeTo<usize>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for RangeToInclusive<usize>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for RangeInclusive<usize>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for RangeFull[src]

type Kind = IsStdKind

type This = Self

impl<T> FormatMarker for Option<NonNull<T>>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroU8>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroI8>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroU16>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroI16>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroU32>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroI32>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroU64>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroI64>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroU128>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroI128>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroUsize>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<NonZeroIsize>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<u8>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<i8>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<u16>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<i16>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<u32>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<i32>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<u64>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<i64>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<u128>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<i128>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<usize>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<isize>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Option<bool>[src]

type Kind = IsStdKind

type This = Self

impl<'a> FormatMarker for Option<&'a str>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroU8[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroI8[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroU16[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroI16[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroU32[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroI32[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroU64[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroI64[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroU128[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroI128[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroUsize[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for NonZeroIsize[src]

type Kind = IsStdKind

type This = Self

impl<T> FormatMarker for NonNull<T>[src]

type Kind = IsStdKind

type This = Self

impl<T: ?Sized> FormatMarker for PhantomData<T>[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for PhantomPinned[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for AtomicOrdering[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Ordering[src]

type Kind = IsStdKind

type This = Self

Loading content...

Implementors

impl FormatMarker for ()[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for Point3[src]

type Kind = IsNotStdKind

type This = Self

impl FormatMarker for Unit[src]

type Kind = IsNotStdKind

type This = Self

impl FormatMarker for AsciiStr<'_>[src]

type Kind = IsNotStdKind

type This = Self

impl FormatMarker for bool[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for i8[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for i16[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for i32[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for i64[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for i128[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for isize[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for str[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for u8[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for u16[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for u32[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for u64[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for u128[src]

type Kind = IsStdKind

type This = Self

impl FormatMarker for usize[src]

type Kind = IsStdKind

type This = Self

impl<'a> FormatMarker for Sliced<&'a str, Range<usize>>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<&'a str, RangeFrom<usize>>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<&'a str, RangeFull>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<&'a str, RangeInclusive<usize>>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<&'a str, RangeTo<usize>>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<&'a str, RangeToInclusive<usize>>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<AsciiStr<'a>, Range<usize>>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<AsciiStr<'a>, RangeFrom<usize>>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<AsciiStr<'a>, RangeFull>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<AsciiStr<'a>, RangeInclusive<usize>>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<AsciiStr<'a>, RangeTo<usize>>[src]

type Kind = IsNotStdKind

type This = Self

impl<'a> FormatMarker for Sliced<AsciiStr<'a>, RangeToInclusive<usize>>[src]

type Kind = IsNotStdKind

type This = Self

impl<P> FormatMarker for PWrapper<P>[src]

type Kind = IsNotStdKind

type This = Self

impl<T> FormatMarker for *const T[src]

type Kind = IsStdKind

type This = Self

impl<T> FormatMarker for *mut T[src]

type Kind = IsStdKind

type This = Self

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]

type Kind = T::Kind

type This = T::This

impl<T: ?Sized> FormatMarker for &mut T where
    T: FormatMarker
[src]

type Kind = T::Kind

type This = T::This

Loading content...