collect_failable 0.18.0

A trait for collecting values into a container which has an invariant to uphold and whose construction may fail
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::errors::types::SizeHint;

/// A trait for types with a dynamic item capacity, expressed as a [`SizeHint`].
///
/// This is the remaining capacity of the collection,
/// and may change if the collection is modified.
pub trait RemainingCap {
    /// Returns the remaining capacity of this collection as a [`SizeHint`].
    fn remaining_cap(&self) -> SizeHint;
}

/// A trait for types with a static item capacity, expressed as a [`SizeHint`].
///
/// This is the static capacity of the collection when empty, and it should never change.
pub trait FixedCap: RemainingCap {
    /// The static capacity of this collection as a [`SizeHint`].
    const CAP: SizeHint;
}