Trait defmt::Format

source ·
pub trait Format {
    // Required method
    fn format(&self, fmt: Formatter<'_>);
}
Expand description

Trait for types that can be formatted via defmt.

This trait is used by the {:?} format specifier and can format a wide range of types. User-defined types can #[derive(Format)] to get an auto-generated implementation of this trait.

Note: The implementation of #[derive(Format)] assumes that no builtin types are shadowed (for example by defining a struct u8;). This allows it to represent them more compactly.

Example

Usually, an implementation of this trait can be #[derive]d automatically:

use defmt::Format;

#[derive(Format)]
struct Header {
    source: u8,
    destination: u8,
    sequence: u16,
}

Manual implementations can make use of the write! macro:

use defmt::{Format, Formatter, write};

struct Id(u32);

impl Format for Id {
    fn format(&self, fmt: Formatter) {
        // Format as hexadecimal.
        write!(fmt, "Id({:x})", self.0);
    }
}

Required Methods§

source

fn format(&self, fmt: Formatter<'_>)

Writes the defmt representation of self to fmt.

Implementations on Foreign Types§

source§

impl Format for NonZeroI64

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T> Format for PhantomData<T>

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for char

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for NonZeroI128

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for NonZeroU8

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T> Format for Rc<T>where T: ?Sized + Format,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for i16

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<A, B> Format for Zip<A, B>where A: Format, B: Format,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T> Format for &mut Twhere T: Format + ?Sized,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<Idx> Format for RangeFrom<Idx>where Idx: Format,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<Idx> Format for RangeTo<Idx>where Idx: Format,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T> Format for Box<T>where T: ?Sized + Format,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<'a, T> Format for Cow<'a, [T]>where T: 'a + Format, [T]: ToOwned<Owned = Vec<T>>,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for isize

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T> Format for *mut Twhere T: ?Sized,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for TryFromIntError

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T, const N: usize> Format for [T; N]where T: Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for NonZeroUsize

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T0: Format, T1: Format, T2: Format, T3: Format, T4> Format for (T0, T1, T2, T3, T4)where T4: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<Idx> Format for Range<Idx>where Idx: Format,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T0: Format, T1: Format, T2: Format, T3: Format, T4: Format, T5: Format, T6: Format, T7: Format, T8: Format, T9> Format for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)where T9: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for ()

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for NonZeroIsize

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for NonZeroU64

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<'a, T> Format for Iter<'a, T>where T: Format + 'a,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for BorrowError

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for u16

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<'a> Format for Cow<'a, str>

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for bool

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for NonZeroI8

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for u32

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T> Format for *const Twhere T: ?Sized,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for Duration

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T0: Format, T1: Format, T2: Format, T3> Format for (T0, T1, T2, T3)where T3: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for f32

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T> Format for [T]where T: Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T> Format for Cell<T>where T: Format + Copy,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T0: Format, T1: Format, T2: Format, T3: Format, T4: Format, T5: Format, T6> Format for (T0, T1, T2, T3, T4, T5, T6)where T6: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T0> Format for (T0,)where T0: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for str

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for usize

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T> Format for &Twhere T: Format + ?Sized,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T0: Format, T1: Format, T2: Format, T3: Format, T4: Format, T5> Format for (T0, T1, T2, T3, T4, T5)where T5: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for String

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for NonZeroI32

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for NonZeroI16

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for BorrowMutError

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for Infallible

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T0: Format, T1: Format, T2: Format, T3: Format, T4: Format, T5: Format, T6: Format, T7: Format, T8> Format for (T0, T1, T2, T3, T4, T5, T6, T7, T8)where T8: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for TryFromSliceError

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for NonZeroU128

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T0: Format, T1: Format, T2: Format, T3: Format, T4: Format, T5: Format, T6: Format, T7: Format, T8: Format, T9: Format, T10: Format, T11> Format for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)where T11: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for RangeFull

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for i32

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for NonZeroU16

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for i128

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for NonZeroU32

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for u128

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for u8

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T0: Format, T1: Format, T2: Format, T3: Format, T4: Format, T5: Format, T6: Format, T7> Format for (T0, T1, T2, T3, T4, T5, T6, T7)where T7: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T, E> Format for Result<T, E>where T: Format, E: Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<'a, T> Format for ChunksExact<'a, T>where T: Format + 'a,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for f64

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T0: Format, T1: Format, T2: Format, T3: Format, T4: Format, T5: Format, T6: Format, T7: Format, T8: Format, T9: Format, T10> Format for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)where T10: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for i64

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T> Format for RefCell<T>where T: Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<Idx> Format for RangeInclusive<Idx>where Idx: Format,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for i8

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl Format for Layout

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl Format for u64

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T0: Format, T1: Format, T2> Format for (T0, T1, T2)where T2: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T> Format for Option<T>where T: Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<'a, T> Format for Windows<'a, T>where T: Format + 'a,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<T0: Format, T1> Format for (T0, T1)where T1: ?Sized + Format,

source§

fn format(&self, _fmt: Formatter<'_>)

source§

impl<T> Format for Vec<T>where T: Format,

source§

fn format(&self, fmt: Formatter<'_>)

source§

impl<Idx> Format for RangeToInclusive<Idx>where Idx: Format,

source§

fn format(&self, fmt: Formatter<'_>)

Implementors§

source§

impl Format for Str

source§

impl<T: Debug + ?Sized> Format for Debug2Format<'_, T>

source§

impl<T: Display + ?Sized> Format for Display2Format<'_, T>