Skip to content
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

Feature Request: raise_results() adapter #898

Closed
w-utter opened this issue Mar 8, 2024 · 1 comment
Closed

Feature Request: raise_results() adapter #898

w-utter opened this issue Mar 8, 2024 · 1 comment
Labels
fallible-iterator Iterator of results/options

Comments

@w-utter
Copy link

w-utter commented Mar 8, 2024

this iterator would be a wrapper for iterator.process_results(|items| items.map(|item| item)) when either raising the first error, or successfully raising an impl Iterator<Item = Result<T, E>> into a Result<impl Iterator<Item = T>, E>.

I find this particularily useful when using iterator.collect::<Result<Vec<_>, _>>() or likewise is not possible, say with a custom allocator (as collect_into does not to collect into a result of items at the moment) or in a nostd context. This would also provide a more ergonomic way of using the aforementioned proces_results adapter

@Philippe-Cholet
Copy link
Member

Philippe-Cholet commented Mar 8, 2024

The issue here is that to get a Result, we need to consume (at least partially) the iterator and therefore collect the intermediary Ok elements, which necessarily allocate. Something like

#[cfg(feature = "use_alloc")]
fn try_collect_iter<...>(&mut self) -> Result<VecIntoIter<T>, E> {
    iterator.collect::<Result<Vec<_>>, _>()?.into_iter()
}

or

#[cfg(feature = "use_alloc")]
fn try_collect_vec<...>(&mut self) -> Result<Vec<T>, E> {
    iterator.collect()
}

I'm not sure we want to add more result shortcuts as it might/should be part of #844.

@Philippe-Cholet Philippe-Cholet added the fallible-iterator Iterator of results/options label Mar 8, 2024
@w-utter w-utter closed this as completed Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fallible-iterator Iterator of results/options
Projects
None yet
Development

No branches or pull requests

2 participants