Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write! macro #263

Merged
merged 4 commits into from
Nov 24, 2020
Merged

write! macro #263

merged 4 commits into from
Nov 24, 2020

Conversation

jonas-schievink
Copy link
Contributor

@jonas-schievink jonas-schievink commented Nov 16, 2020

Closes #104
Closes #97 (winfo! is removed)

@jonas-schievink jonas-schievink added the pr waits on: author Pull Request requires changes from the author label Nov 16, 2020
@jonas-schievink jonas-schievink changed the title [wip] write! macro write! macro Nov 23, 2020
@jonas-schievink jonas-schievink marked this pull request as ready for review November 23, 2020 17:42
@jonas-schievink
Copy link
Contributor Author

This now implements a more limited, but backwards-compatible version where you can only call write! once per Format impl. In 0.2, we'll allow arbitrarily many calls and introduce a dedicated tag for write!, which lets us distinguish it from derived Format impls.

@jonas-schievink jonas-schievink added pr waits on: review Pull Request is waiting on review and removed pr waits on: author Pull Request requires changes from the author labels Nov 23, 2020
Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is excellent work.

before publishing defmt 0.1.2 we should mention this feature in the book but that can be done in a follow-up PR so I'll hit the merge button now

@@ -750,44 +750,6 @@ pub fn debug_assert_ne_(ts: TokenStream) -> TokenStream {
.into()
}

// TODO share more code with `log`
#[proc_macro]
pub fn winfo(ts: TokenStream) -> TokenStream {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

}

defmt::info!(
"nested `Format` impls using `write!`: {:?}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 (this is a test case I was going to suggest)

impl Format for MyStruct {
fn format(&self, fmt: &mut defmt::Formatter) {
defmt::write!(fmt, "one");
defmt::write!(fmt, "two");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@japaric japaric merged commit 84bcc9e into main Nov 24, 2020
@japaric japaric deleted the write branch November 24, 2020 17:08
@japaric japaric mentioned this pull request Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr waits on: review Pull Request is waiting on review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

syntax checked write! macro align winfo!() with info!()
2 participants