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! for RichTextBuilder #1596

Merged
merged 6 commits into from
Feb 17, 2021

Conversation

maan2003
Copy link
Collaborator

No description provided.

@maan2003 maan2003 requested a review from cmyr February 17, 2021 18:23
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Interesting. I trust you've found this useful for something and it's not very intrusive, so I'm happy to merge. A few little questions inline, but nothing blocking.

/// Glue for usage of the write! macro.
///
/// This method should generally not be invoked manually, but rather through the write! macro itself.
pub fn write_fmt(&mut self, fmt: std::fmt::Arguments<'_>) -> AttributesAdder {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add #[doc(hidden)] on this, since it's really an implementation detail and doesn't need to show up in public docs?

Hmm, should we be implementing the Write trait directly? Is this depending on an implementation detail of the macro, where it calls write_fmt with no qualifiers, instead of doing like Write::write_fmt(writer, args)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't implement Write because it returns a Result, I wanted it to feel more like format!.

Is this depending on an implementation detail of the macro?

the docs say it just needs something with write_fmt method.

The writer may be any value with a write_fmt method; generally this comes from an implementation of either the fmt::Write or the io::Write trait.

@maan2003
Copy link
Collaborator Author

you've found this useful for something and it's not very intrusive.

I found myself doing a lot of builder.push(&format!(....)). The first thought was to make push take impl Display.
which will be make it builder.push(format_args!(...)). write! is just a cleaner interface.

@cmyr
Copy link
Member

cmyr commented Feb 17, 2021

It's possible this also saves us an intermediate allocation, although I'm not sure about this part.

@cmyr cmyr merged commit b9070eb into linebender:master Feb 17, 2021
@maan2003 maan2003 deleted the write-for-rich-text-builder branch February 18, 2021 02:09
richard-uk1 pushed a commit to richard-uk1/druid that referenced this pull request Apr 6, 2021
* write! for RichTextBuilder

* panic on formatting error

* Fix doc test

* Make write_fmt doc hidden

Co-authored-by: Colin Rofls <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants