-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* `setup`: Deduplicate setup * `setup-app`: name `cargo.toml`; add `defmt-itm` * `macros`: Language * `primitives`: Table-ize and drop `u24` (got dropped in (#521)) * `str`: Add links to doc-rs * ...
- Loading branch information
1 parent
6344d62
commit 37d05b9
Showing
16 changed files
with
267 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,47 @@ | ||
# Format slices / arrays | ||
|
||
The `{=[?]}` parameter can be used to log a slices of values that implement the `Format` trait. | ||
The expected argument is a slice. | ||
> The `{=[?]}` parameter can be used to log a slice of values that implement the `Format` trait. | ||
``` rust | ||
# extern crate defmt; | ||
# use defmt::{Format, info}; | ||
# use defmt::Format; | ||
# | ||
#[derive(Format)] | ||
struct X { | ||
y: u16, | ||
z: u8, | ||
} | ||
let xs: &[X] = &[/* .. */]; | ||
info!("xs={=[?]}", xs); | ||
|
||
let xs: &[X] = &[ /* .. */ ]; | ||
defmt::info!("xs={=[?]}", xs); | ||
``` | ||
|
||
Note that for slices of bytes `{=[u8]}` should be preferred as it's better compressed. | ||
`[T] where T: Format` also implements the `Format` trait so it's possible to format `[T]` with `{=?}` but `{=[?]}` uses slightly less bandwidth. | ||
* The expected argument is a slice. | ||
|
||
* Note that for slices of bytes, `{=[u8]}` should be preferred as it's better compressed. | ||
|
||
* `[T] where T: Format` also implements the `Format` trait so it's possible to format `[T]` with `{=?}` but `{=[?]}` uses slightly less bandwidth. | ||
|
||
If you have an array of types that implement the `Format` trait, instead of a slice. You should use | ||
the `{=[?; N]}` parameter (where `N` is a number); this saves bandwidth compared to `{=[?]}`. | ||
|
||
## Arrays | ||
|
||
If you have an array of types that implement the `Format` trait, you should use | ||
the `{=[?; N]}` parameter (where `N` is the number of elements); this saves bandwidth compared to `{=[?]}`. | ||
|
||
``` rust | ||
# extern crate defmt; | ||
# use defmt::{Format, info}; | ||
# use defmt::Format; | ||
# | ||
#[derive(Format)] | ||
struct X { | ||
y: u16, | ||
z: u8, | ||
} | ||
|
||
let xs: [X; 2] = [ | ||
# X { y: 1, z: 2 }, | ||
# X { y: 3, z: 4 }, | ||
// .. | ||
]; | ||
info!("xs={=[?; 2]}", xs); | ||
defmt::info!("xs={=[?; 2]}", xs); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.