-
-
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.
662: Add attributes for Format derive to use Debug2Format on specific fields r=jonas-schievink a=mattico I often have structs or enums where most fields impl `Format`, but a few third-party types do not. It is a pain to have to manually impl `Format` for the whole type when only one field doesn't work. I added an attribute that lets you override specific fields to use `Debug2Format` or `Display2Format` like so: ```rust #[derive(defmt::Format)] pub enum Error { Serial(serial::Error), Timeout(us_timer::TimeoutError), Serde(#[defmt(Debug2Format)] serde_json::Error), ResponseTooLarge, } ``` Co-authored-by: Matt Ickstadt <mattico8@gmail.com>
- Loading branch information
Showing
13 changed files
with
249 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#[derive(defmt::Format)] | ||
struct S { | ||
#[defmt()] | ||
f: bool, | ||
} | ||
|
||
fn main() {} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: expected 1 attribute argument | ||
--> $DIR/derive-empty-attr.rs:3:7 | ||
| | ||
3 | #[defmt()] | ||
| ^^^^^^^ |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#[derive(defmt::Format)] | ||
struct S { | ||
#[defmt(FooBar)] | ||
f: bool, | ||
} | ||
|
||
fn main() {} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: expected `Debug2Format` or `Display2Format` | ||
--> $DIR/derive-invalid-attr-arg.rs:3:13 | ||
| | ||
3 | #[defmt(FooBar)] | ||
| ^^^^^^ |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[derive(defmt::Format)] | ||
struct S { | ||
#[defmt(Debug2Format)] | ||
#[defmt()] | ||
f: bool, | ||
} | ||
|
||
fn main() {} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: multiple `defmt` attributes not supported | ||
--> $DIR/derive-multi-attr.rs:3:5 | ||
| | ||
3 | / #[defmt(Debug2Format)] | ||
4 | | #[defmt()] | ||
5 | | f: bool, | ||
| |___________^ |
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.