Skip to main content

try_collect_exact

Function try_collect_exact 

Source
fn try_collect_exact<T, I>(iter: I) -> Result<Vec<T>, &'static str>
where I: IntoIterator<Item = T>,
Expand description

Collects an exact-size-hint iterator into a Vec, failing cleanly on allocation failure instead of aborting (issue #67).

The exact reservation means the push loop below can never reallocate: either the whole vector is built, or we return Err having allocated nothing (beyond the failed reservation itself).