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

Expose write_to for DelayedFormat #1654

Merged
merged 1 commit into from
Jan 23, 2025
Merged

Conversation

tugtugtug
Copy link

Request for #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.

supersedes #1653

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.02%. Comparing base (5f2f5a8) to head (1bbc3ef).
Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

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);
/// ```
Copy link
Member

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.

Copy link
Author

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.
Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

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

Thanks!

@djc djc merged commit 4c42ee5 into chronotope:main Jan 23, 2025
35 checks passed
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