-
Notifications
You must be signed in to change notification settings - Fork 313
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 map_err
and err_into
iterator adapters
#714
base: master
Are you sure you want to change the base?
Conversation
Not entirely sure about procedure, but is there a good reason not to merge this sort of thing? particularly |
This is a place where the questions come down to clutter and discoverability and worth-it-ness, to me. Is it really clearer to have this? Would it be worth bothering writing a lint to detect the manual way -- with Given that I wish we had a better way of doing conditional bounds in return-position (Not to mention that |
That sounds rather reasonable haha. I was sure there'd be good reason for it not already existing considering It could definitely just be me not being super comfortable with iterators of results. I mostly went looking for it because I am janking anyhow errors around in some application code I wrote, and I found an open PR which served to peak my curiosity. Thank you for your input! |
Note that for things like
to then make it possible to write And that way it's still a normal Oh, and obligatory mention of https://doc.rust-lang.org/stable/rust-by-example/error/iter_result.html if you're consuming iterators over results. |
First, I agree with scottmcm. Skimming the code, I don't think there is a need for a new trait As labelled as
fallible-iterator
|
+1 Tying these special case If I insist on one-liners, I'd prefer a function that curries
And use it for all mappings over results:
I get this is controversial, but imho we should ditch the special case mappers. @jswrenn @Philippe-Cholet What do you think? |
I think we might want to deprecate some things once we do #844 (we might want the current discussion there) and there is no rush to deprecate them (0.13.0 already has quite some changes). Even if your alternative is a 1-liner, I would not call it convenient. Just pasting some playground. |
This PR adds
map_err
anderr_into
methods toItertools
..map_err(f)
is just like.map_ok(f)
, but it appliesf
to eachResult::Err
value..err_into()
is simply.map_err(Into::into)
.These methods already exist on
Stream
s ("async iterators") inTryStreamExt
, and I think the ergonomics are quite pleasant. E.g., the following pattern becomes less cumbersome:I've included tests for iterator specialization, and doctests for both methods. Implementation details live in
crate::adaptors::map
, alongsideMapOk
andMapInto
.Let me know if there's any feedback or concerns; or if this feature is just not needed.
Thanks!