Expose write_to for DelayedFormat#1654
Merged
djc merged 1 commit intochronotope:mainfrom Jan 23, 2025
Merged
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
djc
reviewed
Jan 23, 2025
src/format/formatting.rs
Outdated
Comment on lines
+112
to
+130
| /// ### 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); | ||
| /// ``` |
Member
There was a problem hiding this comment.
Yes, also not interested in having the Write adapter in the examples.
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
jtmoon79
added a commit
to jtmoon79/super-speedy-syslog-searcher
that referenced
this pull request
Mar 15, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Request for #1649
Displayis slower thanwrite_toin that specific use case.supersedes #1653