Introduce Arena::try_alloc_from_iter.

This commit is contained in:
Camille GILLOT
2025-04-19 00:25:08 +00:00
parent 191df20fca
commit d0d3021bf8
2 changed files with 47 additions and 33 deletions

View File

@@ -181,16 +181,8 @@ impl<'a> ConditionSet<'a> {
arena: &'a DroplessArena,
f: impl Fn(Condition) -> Option<Condition>,
) -> Option<ConditionSet<'a>> {
let mut all_ok = true;
let set = arena.alloc_from_iter(self.iter().map_while(|c| {
if let Some(c) = f(c) {
Some(c)
} else {
all_ok = false;
None
}
}));
all_ok.then_some(ConditionSet(set))
let set = arena.try_alloc_from_iter(self.iter().map(|c| f(c).ok_or(()))).ok()?;
Some(ConditionSet(set))
}
}