-
-
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.
529: Refactor user-guide of `book` r=Urhengulas a=Urhengulas This PR aims to update the user guide of the book to the dirbaio PRs and is doing quite some refactoring on the side. Preview: https://deploy-preview-529--admiring-dubinsky-56dff5.netlify.app Co-authored-by: Johann Hemmann <johann.hemmann@code.berlin>
- Loading branch information
Showing
17 changed files
with
294 additions
and
194 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 `{=[?]}` parameter can be used to log a slice of values that implement the `Format` trait. | ||
The expected argument is a slice. | ||
|
||
``` 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. | ||
|
||
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 `{=[?]}`. | ||
> 💡 Note that for slices of bytes, `{=[u8]}` should be preferred as it's better compressed. | ||
|
||
## 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 }, | ||
# 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
Oops, something went wrong.