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§
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<'a, T> Format for ChunksExact<'a, T>where
T: 'a + Format,
impl<'a, T> Format for ChunksExact<'a, T>where
T: 'a + Format,
Source§impl<Idx> Format for RangeInclusive<Idx>where
Idx: Format,
impl<Idx> Format for RangeInclusive<Idx>where
Idx: Format,
Source§impl<Idx> Format for RangeToInclusive<Idx>where
Idx: Format,
impl<Idx> Format for RangeToInclusive<Idx>where
Idx: Format,
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
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§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
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§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
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§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
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§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
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§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
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§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
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§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
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§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
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§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
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§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
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§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
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§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
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§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
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§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)
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)
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)
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)
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> Format for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> Format for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> Format for (T0, T1, T2, T3, T4, T5, T6, T7, T8)
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> Format for (T0, T1, T2, T3, T4, T5, T6, T7, T8)
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7> Format for (T0, T1, T2, T3, T4, T5, T6, T7)
impl<T0, T1, T2, T3, T4, T5, T6, T7> Format for (T0, T1, T2, T3, T4, T5, T6, T7)
Source§impl<T0, T1, T2, T3, T4, T5, T6> Format for (T0, T1, T2, T3, T4, T5, T6)
impl<T0, T1, T2, T3, T4, T5, T6> Format for (T0, T1, T2, T3, T4, T5, T6)
Source§impl<T0, T1, T2, T3, T4, T5> Format for (T0, T1, T2, T3, T4, T5)
impl<T0, T1, T2, T3, T4, T5> Format for (T0, T1, T2, T3, T4, T5)
Source§impl<T0, T1, T2, T3, T4> Format for (T0, T1, T2, T3, T4)
impl<T0, T1, T2, T3, T4> Format for (T0, T1, T2, T3, T4)
Source§impl<T0, T1, T2, T3> Format for (T0, T1, T2, T3)
impl<T0, T1, T2, T3> Format for (T0, T1, T2, T3)
Source§impl<T0, T1, T2> Format for (T0, T1, T2)
impl<T0, T1, T2> Format for (T0, T1, T2)
Implementors§
impl Format for BatteryStatewhere
BatteryStatus: Format,
impl Format for BatteryStatus
impl Format for DeviceState
impl Format for Direction
impl Format for EndpointAddress
Available on crate feature
defmt only.