use fluent_result::into::IntoResult;
#[sealed::sealed]
pub trait EnsureEmpty: Iterator + Sized {
fn ensure_empty(mut self) -> Result<(), NotEmpty<Self>> {
self.next().map_or_else(|| Ok(()), |item| NotEmpty { iter: self, item }.into_err())
}
}
#[sealed::sealed]
impl<I: Iterator> EnsureEmpty for I {}
#[derive(Debug, thiserror::Error)]
#[error("iterator is not empty")]
pub struct NotEmpty<I: Iterator> {
pub iter: I,
pub item: I::Item,
}