-
Notifications
You must be signed in to change notification settings - Fork 309
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
Removed lifetimes in "process_results" in favour of using NonNull #897
Removed lifetimes in "process_results" in favour of using NonNull #897
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #897 +/- ##
==========================================
+ Coverage 94.38% 94.65% +0.26%
==========================================
Files 48 48
Lines 6665 6754 +89
==========================================
+ Hits 6291 6393 +102
+ Misses 374 361 -13 ☔ View full report in Codecov by Sentry. |
let mut error = Ok(()); | ||
let mut err = Ok(()); | ||
|
||
//SAFETY: the pointer to err will always be valid thoughout the fns lifetime |
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'm pretty sure this is incorrect.
By removing the lifetime you decoupled its lifetime from the closure context, which means I could move it out of the FnOnce
closure to something that lives longer.
Try something like this https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7d22b4472f094ec36a45b879d6b8e7df
use itertools::*;
fn main() {
let mut foo = None;
let it = std::iter::repeat(Err::<String, String>("hello".to_string()));
itertools::process_results(it, |x| {
foo = Some(x);
Err::<String, String>("world".to_string())
});
dbg!(foo.unwrap().next());
}
today and you get "error: borrowed data escapes outside of closure".
But if you take the lifetime off of the ProcessResults
struct, it'd be allowed, and would be holding a NonNull
to a local from the function you've already left, which is definitely not ok if it uses it.
Note that while this is an obvious wish, it's fundamentally not possible while being lazy. No matter how much of the iterator you've looked at and only seen And that's called |
Ah, wrote this a little hastily while trying to get |
There were some lifetime issues that I was running into trying to directly raise an
impl Iterator<Item = Result<T, E>>
to aResult<impl Iterator<Item = T>, E>
saying something along the lines that the lifetimes were incompatible. However when changing to NonNull these errors went away, and works the same way as before.This will coincide with a wrapper fn that handles doing
iterator.into_iter().process_results(|iter| iter.map(|item| item))
which I will work on shortly.Just as a note, In the future this api should probably take in all T who implement Try just so that this would be possible with options and other user generated objects, but that is out of the scope of this pr.