-
Notifications
You must be signed in to change notification settings - Fork 532
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
Add MappedLocalTime::try_map
#1533
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1533 +/- ##
=======================================
Coverage 91.82% 91.82%
=======================================
Files 40 40
Lines 18345 18345
=======================================
Hits 16846 16846
Misses 1499 1499 ☔ View full report in Codecov by Sentry. |
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.
This PR on its own doesn't look well-motivated... I'd probably keep this commit in the Cache
PR but am okay if you want to get it merged first.
src/offset/mod.rs
Outdated
/// | ||
/// Returns `MappedLocalTime::None` if the function returns `None`. | ||
#[must_use] | ||
pub(crate) fn try_map<U, F: FnMut(T) -> Option<U>>(self, mut f: F) -> MappedLocalTime<U> { |
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.
I think the Option
variant of this is called and_then()
, maybe reuse that name?
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.
👍 and_then()
is better.
Not sure what you mean. Maybe as another motivation: to implement addition and substraction for a But I have to admit I'm not sure if the current two uses in this PR for the 0.4 versions will remain useful for 0.5 with one of the plans in 1448#issuecomment-1987220921. So the method is |
Ah, sorry, I missed that there are sort of two users for the new method. Looks a little surprising because one of the callers did not previously have the extensive logic implemented in the method. |
Yes, that was the issue I set out to fix 😄. Sorry for not saying so better. |
Passing on one error in
unix::Cache::offset
requires a match that is very similar to the one inTimeZone::from_local_datetime
.I added
MappedLocalTime::try_map
that returnsMappedLocalTime::None
that can be used in both places.For the 0.5.x branch it will be easy to convert this method to return a
Result
instead.