-
Notifications
You must be signed in to change notification settings - Fork 536
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
Saturating operations #1579
Comments
I encountered a case where I need to add pub fn generate_date_ranges(
start: NaiveDate,
end: NaiveDate,
step: Duration,
) -> Vec<RangeInclusive<NaiveDate>> {
let mut date_range = Vec::new();
let mut next_start = start;
while next_start < end {
let next_end = next_start.saturating_add(step);
date_range.push(RangeInclusive::new(next_start, next_end));
next_start = next_end;
}
date_range
} |
A single person requesting this feature is not enough, in this case, to add this feature, I think. Let's keep this open and see if other people turn up that want/need this? |
For integers saturation operations make sense because they have a commonly agreed-upon range. |
Hey @djc. I'm writing a code that needs to pass Maybe I landed on a wrong issue, but the main comment is that I'd like a method that gracefully handles gaps in time and skips them when doing subtraction even if it doesn't saturate at the bounds of allowed date-time values. I can just use a default |
If the time zone is UTC there are no gaps, If the time zone is |
@pitdicker was thinking about this: if the result of a calculation is |
Quoting from #1448:
Sorry for being absent again. I really need to continue working on this for 0.5... |
Oh, right... I was confused by the method signature and docs mentioning gaps. It is indeed basically infallible in UTC, so there is no problem in my case |
|
Saturating add/sub would be great in my case. For my use case, I have a "stale duration" variable, where a piece of data is only considered valid if it's not stale. However, in some cases I don't want to have a stale duration, and whilst I could wrap it in an option, |
Suggest you submit a PR with any suggestions you have if they fit into the current API. |
saturating_*
methods might be quite useful. They are present in standard library for primitive types, so the use case can be quite frequent (?).I found only one mention of saturation in this repo: "...library users could implement some saturating_* methods...".
Since there seems to be no separate discussion about this, I suggest to consider this implementation here.
The text was updated successfully, but these errors were encountered: