Skip to content

Conversation

BigPapa314
Copy link

Fixes #1663

Copy link

codecov bot commented Mar 3, 2025

Codecov Report

Attention: Patch coverage is 96.80851% with 6 lines in your changes missing coverage. Please review.

Project coverage is 91.13%. Comparing base (fa957cc) to head (d89f8f9).

Files with missing lines Patch % Lines
src/format/formatting.rs 85.36% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1672      +/-   ##
==========================================
+ Coverage   91.06%   91.13%   +0.06%     
==========================================
  Files          37       37              
  Lines       17454    17565     +111     
==========================================
+ Hits        15895    16007     +112     
+ Misses       1559     1558       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BigPapa314
Copy link
Author

Hmm the codecov/project task seams to be stuck. Can someone have a look?

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.

Sorry for the very long delay...

(Also needs a rebase.)

Comment on lines +202 to +217
#[cfg(not(feature = "alloc"))]
impl Numeric {
/// Adds the with of the padding to the numeric
///
/// Should be removed if the padding width is added to the `Pad` enum.
pub fn with_padding(self, _width: usize) -> Self {
self
}

/// Gets the numeric and padding width from the numeric
///
/// Should be removed if the padding width is added to the `Pad` enum.
pub fn unwrap_padding(&self) -> (&Self, usize) {
(self, 0)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this useful? I don't think these should be part of the public API.

Copy link
Author

Choose a reason for hiding this comment

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

Becauase we don't add the padding width to the Pad enum and try to add it using dynamic memory allocation to the Numeric enum we have multiple cases to handle if we want to work with padding. Because the lib can also be used without dynamic memory allocation the code has to be deactivated in that cases. This is done by the "with_padding" and "unwrap_padding" functions. Because the Numeric enum is public this functions should also be public to help working with the padding.

(0, Pad::None) => {}
(0, Pad::Space) => w.write_char(' ')?,
(tens, _) => w.write_char((b'0' + tens) as char)?,
// unpack padding width if provided
Copy link
Member

Choose a reason for hiding this comment

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

I want your diff to have minimal changes to the structure of the code, or to isolate structural (but non-functional) changes in a separate commit. Is that feasible? The current iteration seems pretty hard to review.

Copy link
Author

Choose a reason for hiding this comment

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

The original code only had the oportunity to have exactly one or two padding signs. So there where special functions "write_one" and "write_two" to exactly do that. Because we now have a dynamic amount of padding signs it whould make the code more complex to have some kind of selection logic for "write_xxx" methods when we already had a method to write any amount of padding signs.

@BigPapa314
Copy link
Author

In general this PR should be a proposal how it whould look like if we add the padding width to the Numeric enum and not to the Pad enum where it whould belong to. My conclusion is:

Advantages:

  • The API might be stable as the Numeric enum is #[non_exhaustive]

Drawbacks:

  • The API only works with dynamic memory allocation
  • The work with the padding width is cumbersome and needs more API changes that have to be removed when the padding width is moved to the Pad enum in the future

I think we should postpone the changes untill we can add the padding with to where it should be so that we can implement it in a minimal invasive and maximal compatible way.

@djc
Copy link
Member

djc commented Jul 14, 2025

I think we should postpone the changes untill we can add the padding with to where it should be so that we can implement it in a minimal invasive and maximal compatible way.

Okay, but I have no concrete plans nor much motivation to work on chrono 0.5, so that might mean postponing more or less indefinitely.

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.

Add padding size to Pad::Zero or Pad::Space
2 participants