-
Notifications
You must be signed in to change notification settings - Fork 593
Expose write_to for DelayedFormat
#1654
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1654 +/- ##
==========================================
+ Coverage 91.01% 91.02% +0.01%
==========================================
Files 37 37
Lines 17342 17366 +24
==========================================
+ Hits 15784 15808 +24
Misses 1558 1558 ☔ View full report in Codecov by Sentry. |
7e94b89 to
2106d5b
Compare
2106d5b to
12e7126
Compare
src/format/formatting.rs
Outdated
| /// ### Writing to a Vec | ||
| /// ``` | ||
| /// // wrapper to allow reuse of the existing string based | ||
| /// // writers | ||
| /// struct IoWriter<W: std::io::Write> { | ||
| /// writer: W, | ||
| /// } | ||
| /// impl<W: std::io::Write> std::fmt::Write for IoWriter<W> { | ||
| /// #[inline] | ||
| /// fn write_str(&mut self, s: &str) -> std::fmt::Result { | ||
| /// self.writer.write_all(s.as_bytes()).map_err(|_| std::fmt::Error) | ||
| /// } | ||
| /// } | ||
| /// let dt = chrono::DateTime::from_timestamp(1643723400, 123456789).unwrap(); | ||
| /// let df = dt.format("%Y-%m-%d %H:%M:%S%.9f"); | ||
| /// let w: Vec<u8> = Vec::new(); | ||
| /// let mut writer = IoWriter { writer: w }; | ||
| /// let _ = df.write_to(&mut writer); | ||
| /// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, also not interested in having the Write adapter in the examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Request for chronotope#1649 - renamed format to write-to and made it public. - added unittests - added benchmarks to compare and show `Display` is slower than `write_to` in that specific use case.
12e7126 to
1bbc3ef
Compare
djc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Request for #1649
Displayis slower thanwrite_toin that specific use case.supersedes #1653