#[cfg(feature = "use_std")] use std::error::Error; use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
use std::iter::ExactSizeIterator;
use either::Either;
usecrate::size_hint;
/// Iterator returned for the error case of `IterTools::exactly_one()` /// This iterator yields exactly the same elements as the input iterator. /// /// During the execution of `exactly_one` the iterator must be mutated. This wrapper /// effectively "restores" the state of the input iterator when it's handed back. /// /// This is very similar to `PutBackN` except this iterator only supports 0-2 elements and does not /// use a `Vec`. #[derive(Clone)] pubstruct ExactlyOneError<I> where
I: Iterator,
{
first_two: Option<Either<[I::Item; 2], I::Item>>,
inner: I,
}
impl<I> ExactlyOneError<I> where
I: Iterator,
{ /// Creates a new `ExactlyOneErr` iterator. pub(crate) fn new(first_two: Option<Either<[I::Item; 2], I::Item>>, inner: I) -> Self { Self { first_two, inner }
}
impl<I> ExactSizeIterator for ExactlyOneError<I> where I: ExactSizeIterator {}
impl<I> Display for ExactlyOneError<I> where I: Iterator,
{ fn fmt(&self, f: &mut Formatter) -> FmtResult { let additional = self.additional_len(); if additional > 0 {
write!(f, "got at least 2 elements when exactly one was expected")
} else {
write!(f, "got zero elements when exactly one was expected")
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.