pub struct CapacityError<T> {
pub capacity: SizeHint,
pub kind: CapacityErrorKind<T>,
}Expand description
An error indicating that a collection or extension operation failed because
of a conflict between the collection’s capacity and the number of items
produced by an Iterator.
This error represents three failure modes, identified by CapacityError::kind.
-
CapacityErrorKind::Bounds— the iterator’s reported size bounds are incompatible with the required capacity, making the operation impossible to satisfy even before iteration begins. -
CapacityErrorKind::Underflow— the iterator produced fewer items than the minimum required by the capacity. -
CapacityErrorKind::Overflow— the iterator produced more items than the maximum allowed by the capacity. The item that caused the overflow is preserved, and may be recovered viaErrorItemProvider. The number of overflowing items is implied to be at least one, but may be more.
§Type Parameters
T: The type of the item in the collection.
Fields§
§capacity: SizeHintThe capacity constraint that was violated.
kind: CapacityErrorKind<T>The specific kind of capacity mismatch that occurred.
Implementations§
Source§impl<T> CapacityError<T>
impl<T> CapacityError<T>
Sourcepub const fn bounds(capacity: SizeHint, hint: SizeHint) -> Self
pub const fn bounds(capacity: SizeHint, hint: SizeHint) -> Self
Creates a new Bounds CapacityError
indicating that hint bounds are incompatible with capacity.
§Arguments
capacity- the capacity of the collectionhint- the size hint of the iterator
§Panics
Panics if capacity and hint overlap.
§Examples
let err = CapacityError::<i32>::bounds(SizeHint::exact(5), SizeHint::exact(2));
assert_eq!(err.capacity, SizeHint::exact(5));
assert_eq!(err.kind, CapacityErrorKind::Bounds { hint: SizeHint::exact(2) });Sourcepub fn ensure_fits<I: Iterator<Item = T>>(
iter: &I,
capacity: SizeHint,
) -> Result<(), Self>
pub fn ensure_fits<I: Iterator<Item = T>>( iter: &I, capacity: SizeHint, ) -> Result<(), Self>
Ensures that iter’s size_hint overlaps
capacity.
§Arguments
iter- theIteratorto check.capacity- the capacity of the collection
§Errors
Returns a Bounds CapacityError if
iter’s size_hint is disjoint
with cap.
§Panics
Panics if iter’s size_hint is invalid.
§Examples
CapacityError::<i32>::ensure_fits(&(1..=5), SizeHint::at_most(5)).expect("Should fit");
let err = CapacityError::<i32>::ensure_fits(&(1..=5), SizeHint::at_most(4))
.expect_err("Should fit");
assert_eq!(err.capacity, SizeHint::at_most(4));
assert_eq!(err.kind, CapacityErrorKind::Bounds { hint: SizeHint::exact(5) });Sourcepub const fn overflow(capacity: SizeHint, overflow: T) -> Self
pub const fn overflow(capacity: SizeHint, overflow: T) -> Self
Creates a new CapacityError indicating that the collection
overflowed capacity.
§Arguments
capacity- The capacity that overflowed.overflow- The item that overflowedcapacity.
§Panics
Panics if capacity is not bounded.
§Examples
let err = CapacityError::overflow(SizeHint::exact(5), 2);
assert_eq!(err.capacity, SizeHint::exact(5));
assert_eq!(err.kind, CapacityErrorKind::Overflow { overflow: 2 });Sourcepub const fn underflow(capacity: SizeHint, count: usize) -> Self
pub const fn underflow(capacity: SizeHint, count: usize) -> Self
Creates a new CapacityError indicating that fewer items were produced
than the minimum required by capacity.
§Arguments
capacity- The capacity that was underflowed.count- The number of items that were produced.
§Panics
Panics if count is greater than or equal to capacity.lower().
§Examples
let err = CapacityError::<i32>::underflow(SizeHint::exact(5), 2);
assert_eq!(err.capacity, SizeHint::exact(5));
assert_eq!(err.kind, CapacityErrorKind::Underflow { count: 2 });Sourcepub const fn underflow_of<C: FixedCap>(count: usize) -> Self
pub const fn underflow_of<C: FixedCap>(count: usize) -> Self
Creates a new CapacityError indicating that fewer items were produced
than the minimum required by C’s FixedCap::CAP.
§Arguments
count- The number of items that were produced.
§Type Parameters
C- A collection with a fixed capaciy.
§Examples
let err = CapacityError::<i32>::underflow_of::<[i32; 5]>(2);
assert_eq!(err.capacity, SizeHint::exact(5));
assert_eq!(err.kind, CapacityErrorKind::Underflow { count: 2 });Trait Implementations§
Source§impl<T: Debug> Debug for CapacityError<T>
impl<T: Debug> Debug for CapacityError<T>
Source§impl<T> Display for CapacityError<T>where
CapacityErrorKind<T>: Display,
impl<T> Display for CapacityError<T>where
CapacityErrorKind<T>: Display,
Source§impl<T> Error for CapacityError<T>
impl<T> Error for CapacityError<T>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl<T> ErrorItemProvider for CapacityError<T>
impl<T> ErrorItemProvider for CapacityError<T>
Source§impl<T> From<CapacityError<T>> for CapacityError<T>
Available on crate feature arrayvec only.
impl<T> From<CapacityError<T>> for CapacityError<T>
arrayvec only.Source§fn from(err: CapacityError<T>) -> Self
fn from(err: CapacityError<T>) -> Self
Source§impl<T: PartialEq> PartialEq for CapacityError<T>
impl<T: PartialEq> PartialEq for CapacityError<T>
impl<T: Eq> Eq for CapacityError<T>
impl<T> StructuralPartialEq for CapacityError<T>
Auto Trait Implementations§
impl<T> Freeze for CapacityError<T>where
T: Freeze,
impl<T> RefUnwindSafe for CapacityError<T>where
T: RefUnwindSafe,
impl<T> Send for CapacityError<T>where
T: Send,
impl<T> Sync for CapacityError<T>where
T: Sync,
impl<T> Unpin for CapacityError<T>where
T: Unpin,
impl<T> UnwindSafe for CapacityError<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoOption for T
impl<T> IntoOption for T
Source§impl<T> IntoResult for T
impl<T> IntoResult for T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.