Skip to content

Commit

Permalink
Merge #391
Browse files Browse the repository at this point in the history
391: 348 format for duration r=jonas-schievink a=Urhengulas

This implements the `trait defmt::Format for core::time::Duration` and also adapts `defmt_macros::write!` to achieve this.

Fixes #348 

Co-authored-by: Urhengulas <johann.hemmann@code.berlin>
  • Loading branch information
bors[bot] and Urhengulas authored Feb 16, 2021
2 parents d457217 + b5503cc commit 42be5f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ pub fn write(ts: TokenStream) -> TokenStream {
let fmt = &write.fmt;
let sym = mksym(&ls, "write", false);
quote!({
let fmt: ::defmt::Formatter<'_> = #fmt;
let fmt: defmt::Formatter<'_> = #fmt;
match (fmt.inner, #(&(#args)),*) {
(_fmt_, #(#pats),*) => {
// HACK conditional should not be here; see FIXME in `format`
Expand Down
12 changes: 11 additions & 1 deletion src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(feature = "unstable-test")]
use crate as defmt;
use defmt_macros::internp;

Expand Down Expand Up @@ -458,3 +457,14 @@ impl Format for core::convert::Infallible {
match *self {}
}
}

impl Format for core::time::Duration {
fn format(&self, fmt: Formatter) {
crate::write!(
fmt,
"Duration {{ secs: {=u64}, nanos: {=u32} }}",
self.as_secs(),
self.subsec_nanos(),
)
}
}

0 comments on commit 42be5f6

Please sign in to comment.