defmt

Trait 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so 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 Location<'_>

Source§

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

Source§

impl Format for PanicInfo<'_>

Source§

fn format(&self, f: 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>

impl Format for Error

impl Format for Error

impl Format for Priority

impl Format for Error

impl Format for Error
where Error: Format,

impl Format for BitOrder

impl Format for Error
where Error: Format,

impl Format for Error
where Error: Format,

impl<C, A, R, T> Format for SpiFuture<C, A, R, T>
where C: ValidConfig, A: Capability,