diff --git a/crates/fj-core/src/objects/handles.rs b/crates/fj-core/src/objects/handles.rs index a17ba356a..eb4085ebc 100644 --- a/crates/fj-core/src/objects/handles.rs +++ b/crates/fj-core/src/objects/handles.rs @@ -61,6 +61,25 @@ impl Handles { self.inner.is_empty() } + /// Return the only item + /// + /// # Panics + /// + /// Panics, if there is more than one item. + pub fn only(&self) -> &Handle { + let mut iter = self.inner.iter(); + let item = iter + .next() + .expect("Requested only item, but no items available"); + + assert!( + iter.next().is_none(), + "Requested only item, but more than one available" + ); + + item + } + /// Return the n-th item pub fn nth(&self, index: usize) -> Option<&Handle> { self.inner.get(index)