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);
    }
}

Note Some implementations of standard types like Vec<T> are hidden behind the alloc feature flag.

Required Methods§

source

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

Writes the defmt representation of self to fmt.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Format for Infallible

source§

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

source§

impl Format for bool

source§

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

source§

impl Format for char

source§

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

source§

impl Format for f32

source§

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

source§

impl Format for f64

source§

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

source§

impl Format for i8

source§

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

source§

impl Format for i16

source§

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

source§

impl Format for i32

source§

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

source§

impl Format for i64

source§

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

source§

impl Format for i128

source§

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

source§

impl Format for isize

source§

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

source§

impl Format for str

source§

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

source§

impl Format for u8

source§

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

source§

impl Format for u16

source§

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

source§

impl Format for u32

source§

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

source§

impl Format for u64

source§

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

source§

impl Format for u128

source§

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

source§

impl Format for ()

source§

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

source§

impl Format for usize

source§

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

source§

impl Format for Layout

source§

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

source§

impl Format for TryFromSliceError

source§

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

source§

impl Format for BorrowError

source§

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

source§

impl Format for BorrowMutError

source§

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

source§

impl Format for TryFromIntError

source§

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

source§

impl Format for RangeFull

source§

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

source§

impl Format for Duration

source§

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

source§

impl Format for NonZeroI8

source§

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

source§

impl Format for NonZeroI16

source§

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

source§

impl Format for NonZeroI32

source§

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

source§

impl Format for NonZeroI64

source§

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

source§

impl Format for NonZeroI128

source§

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

source§

impl Format for NonZeroIsize

source§

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

source§

impl Format for NonZeroU8

source§

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

source§

impl Format for NonZeroU16

source§

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

source§

impl Format for NonZeroU32

source§

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

source§

impl Format for NonZeroU64

source§

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

source§

impl Format for NonZeroU128

source§

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

source§

impl Format for NonZeroUsize

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<'a, T> Format for Iter<'a, T>
where T: Format + 'a,

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<A, B> Format for Zip<A, B>
where A: Format, B: 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<Idx> Format for RangeFrom<Idx>
where Idx: 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<Idx> Format for RangeTo<Idx>
where Idx: Format,

source§

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

source§

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

source§

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

source§

impl<Ret> Format for fn() -> Ret

source§

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

source§

impl<Ret> Format for extern "C" fn() -> Ret

source§

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

source§

impl<Ret> Format for unsafe fn() -> Ret

source§

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

source§

impl<Ret> Format for unsafe extern "C" fn() -> Ret

source§

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

source§

impl<Ret, A> Format for fn(_: A) -> Ret

source§

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

source§

impl<Ret, A> Format for extern "C" fn(_: A) -> Ret

source§

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

source§

impl<Ret, A> Format for unsafe fn(_: A) -> Ret

source§

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

source§

impl<Ret, A> Format for unsafe extern "C" fn(_: A) -> Ret

source§

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

source§

impl<Ret, A, B> Format for fn(_: A, _: B) -> Ret

source§

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

source§

impl<Ret, A, B> Format for extern "C" fn(_: A, _: B) -> Ret

source§

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

source§

impl<Ret, A, B> Format for unsafe fn(_: A, _: B) -> Ret

source§

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

source§

impl<Ret, A, B> Format for unsafe extern "C" fn(_: A, _: B) -> Ret

source§

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

source§

impl<Ret, A, B, C> Format for fn(_: A, _: B, _: C) -> Ret

source§

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

source§

impl<Ret, A, B, C> Format for extern "C" fn(_: A, _: B, _: C) -> Ret

source§

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

source§

impl<Ret, A, B, C> Format for unsafe fn(_: A, _: B, _: C) -> Ret

source§

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

source§

impl<Ret, A, B, C> Format for unsafe extern "C" fn(_: A, _: B, _: C) -> Ret

source§

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

source§

impl<Ret, A, B, C, D> Format for fn(_: A, _: B, _: C, _: D) -> Ret

source§

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

source§

impl<Ret, A, B, C, D> Format for extern "C" fn(_: A, _: B, _: C, _: D) -> Ret

source§

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

source§

impl<Ret, A, B, C, D> Format for unsafe fn(_: A, _: B, _: C, _: D) -> Ret

source§

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

source§

impl<Ret, A, B, C, D> Format for unsafe extern "C" fn(_: A, _: B, _: C, _: D) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E> Format for fn(_: A, _: B, _: C, _: D, _: E) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E> Format for extern "C" fn(_: A, _: B, _: C, _: D, _: E) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E> Format for unsafe fn(_: A, _: B, _: C, _: D, _: E) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E> Format for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F> Format for fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F> Format for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F> Format for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F> Format for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G> Format for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G> Format for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G> Format for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G> Format for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H> Format for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H> Format for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H> Format for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H> Format for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I> Format for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I> Format for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I> Format for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I> Format for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J> Format for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J> Format for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J> Format for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J> Format for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Format for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Format for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Format for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Format for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Format for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Format for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Format for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Ret

source§

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

source§

impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Format for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Ret

source§

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

source§

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

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<T0: Format, T1: Format, T2> Format for (T0, T1, T2)
where T2: ?Sized + Format,

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<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<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<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, 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<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<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<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<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<T> Format for Option<T>
where T: Format,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

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<T> Format for RefCell<T>
where T: Format,

source§

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

source§

impl<T> Format for PhantomData<T>

source§

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

source§

impl<T> Format for NonNull<T>

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<T, const N: usize> Format for [T; N]
where T: 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>