Skip to main content

Format

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

Implementations on Foreign Types§

Source§

impl Format for !

Source§

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

Source§

impl Format for ()

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 Duration

Source§

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

Source§

impl Format for Error

Source§

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

Source§

impl Format for Layout

Source§

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

Source§

impl Format for Location<'_>

Source§

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

Source§

impl Format for NonZero<i8>

Source§

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

Source§

impl Format for NonZero<i16>

Source§

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

Source§

impl Format for NonZero<i32>

Source§

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

Source§

impl Format for NonZero<i64>

Source§

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

Source§

impl Format for NonZero<i128>

Source§

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

Source§

impl Format for NonZero<isize>

Source§

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

Source§

impl Format for NonZero<u8>

Source§

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

Source§

impl Format for NonZero<u16>

Source§

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

Source§

impl Format for NonZero<u32>

Source§

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

Source§

impl Format for NonZero<u64>

Source§

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

Source§

impl Format for NonZero<u128>

Source§

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

Source§

impl Format for NonZero<usize>

Source§

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

Source§

impl Format for PanicInfo<'_>

Source§

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

Source§

impl Format for ParseBoolError

Source§

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

Source§

impl Format for RangeFull

Source§

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

Source§

impl Format for TryFromIntError

Source§

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

Source§

impl Format for TryFromSliceError

Source§

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

Source§

impl Format for Utf8Error

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 usize

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

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, 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 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<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> 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 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> 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> 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 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> 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> 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 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> 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> 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 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> 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> 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 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> 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> 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 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> 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> 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 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> Format for unsafe fn(A, B, C, D, E) -> 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 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> Format for unsafe fn(A, B, C, D) -> 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 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> Format for unsafe fn(A, B, C) -> 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 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> Format for unsafe fn(A, B) -> 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 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> Format for unsafe fn(A) -> 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 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> Format for unsafe fn() -> Ret

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

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<'_>)

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 *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 Cell<T>
where T: Format + Copy,

Source§

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

Source§

impl<T> Format for NonNull<T>

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 PhantomData<T>

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

Source§

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

Source§

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

Source§

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

Implementors§