Struct amplify::confinement::Confined
source · pub struct Confined<C: Collection, const MIN_LEN: usize, const MAX_LEN: usize>(/* private fields */);
Expand description
The confinement for the collection.
Implementations§
source§impl<'c, C, const MIN_LEN: usize, const MAX_LEN: usize> Confined<C, MIN_LEN, MAX_LEN>
impl<'c, C, const MIN_LEN: usize, const MAX_LEN: usize> Confined<C, MIN_LEN, MAX_LEN>
sourcepub fn iter_mut(&'c mut self) -> <&'c mut C as IntoIterator>::IntoIter
pub fn iter_mut(&'c mut self) -> <&'c mut C as IntoIterator>::IntoIter
Returns an iterator that allows modifying each value.
The iterator yields all items from start to end.
source§impl<'c, C, const MIN_LEN: usize, const MAX_LEN: usize> Confined<C, MIN_LEN, MAX_LEN>where
C: KeyedCollection + 'c,
&'c mut C: IntoIterator<Item = (&'c <C as KeyedCollection>::Key, &'c mut <C as KeyedCollection>::Value)>,
impl<'c, C, const MIN_LEN: usize, const MAX_LEN: usize> Confined<C, MIN_LEN, MAX_LEN>where
C: KeyedCollection + 'c,
&'c mut C: IntoIterator<Item = (&'c <C as KeyedCollection>::Key, &'c mut <C as KeyedCollection>::Value)>,
sourcepub fn keyed_values_mut(&'c mut self) -> <&'c mut C as IntoIterator>::IntoIter
pub fn keyed_values_mut(&'c mut self) -> <&'c mut C as IntoIterator>::IntoIter
Returns an iterator that allows modifying each value for each key.
source§impl<C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> Confined<C, MIN_LEN, MAX_LEN>
impl<C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> Confined<C, MIN_LEN, MAX_LEN>
sourcepub fn from_collection_unsafe(col: C) -> Self
pub fn from_collection_unsafe(col: C) -> Self
Constructs confinement over collection which was already size-checked.
§Safety
Panics if the collection size doesn’t fit confinement type requirements.
sourcepub fn try_from(col: C) -> Result<Self, Error>
pub fn try_from(col: C) -> Result<Self, Error>
Tries to construct a confinement over a collection. Fails if the number of items in the collection exceeds one of the confinement bounds.
sourcepub fn try_from_iter<I: IntoIterator<Item = C::Item>>(
iter: I
) -> Result<Self, Error>
pub fn try_from_iter<I: IntoIterator<Item = C::Item>>( iter: I ) -> Result<Self, Error>
Tries to construct a confinement with a collection of elements taken from an iterator. Fails if the number of items in the collection exceeds one of the confinement bounds.
sourcepub fn from_iter_unsafe<I: IntoIterator<Item = C::Item>>(iter: I) -> Self
pub fn from_iter_unsafe<I: IntoIterator<Item = C::Item>>(iter: I) -> Self
Construct a confinement with a collection of elements taken from an iterator. Panics if the number of items in the collection exceeds one of the confinement bounds.
sourcepub fn into_inner(self) -> C
pub fn into_inner(self) -> C
Decomposes into the inner collection type
sourcepub fn push(&mut self, elem: C::Item) -> Result<(), Error>
pub fn push(&mut self, elem: C::Item) -> Result<(), Error>
Attempts to add a single element to the confined collection. Fails if the number of elements in the collection already maximal.
source§impl<C, const MAX_LEN: usize> Confined<C, ZERO, MAX_LEN>where
C: Default + Collection,
impl<C, const MAX_LEN: usize> Confined<C, ZERO, MAX_LEN>where
C: Default + Collection,
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new confinement containing no elements, but with a
pre-allocated storage for the capacity
of elements.
source§impl<C: KeyedCollection, const MIN_LEN: usize, const MAX_LEN: usize> Confined<C, MIN_LEN, MAX_LEN>
impl<C: KeyedCollection, const MIN_LEN: usize, const MAX_LEN: usize> Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MAX_LEN: usize> Confined<C, ONE, MAX_LEN>where
C: Default + KeyedCollection,
impl<C, const MAX_LEN: usize> Confined<C, ONE, MAX_LEN>where
C: Default + KeyedCollection,
sourcepub fn with_key_value(key: C::Key, value: C::Value) -> Self
pub fn with_key_value(key: C::Key, value: C::Value) -> Self
Constructs a confinement with a collection made of a single required key-value pair.
source§impl<const MAX_LEN: usize> Confined<AsciiString, ZERO, MAX_LEN>
impl<const MAX_LEN: usize> Confined<AsciiString, ZERO, MAX_LEN>
source§impl<T, const MIN_LEN: usize, const MAX_LEN: usize> Confined<Vec<T>, MIN_LEN, MAX_LEN>
impl<T, const MIN_LEN: usize, const MAX_LEN: usize> Confined<Vec<T>, MIN_LEN, MAX_LEN>
sourcepub fn from_slice_unsafe(slice: &[T]) -> Selfwhere
T: Clone,
pub fn from_slice_unsafe(slice: &[T]) -> Selfwhere
T: Clone,
Constructs confinement out of slice of items. Does allocation.
§Panics
Panics if the size of the slice doesn’t match the confinement type bounds.
source§impl<T, const MIN_LEN: usize, const MAX_LEN: usize> Confined<Vec<T>, MIN_LEN, MAX_LEN>
impl<T, const MIN_LEN: usize, const MAX_LEN: usize> Confined<Vec<T>, MIN_LEN, MAX_LEN>
source§impl<T, const MIN_LEN: usize, const MAX_LEN: usize> Confined<VecDeque<T>, MIN_LEN, MAX_LEN>
impl<T, const MIN_LEN: usize, const MAX_LEN: usize> Confined<VecDeque<T>, MIN_LEN, MAX_LEN>
sourcepub fn push_from(&mut self, elem: T) -> Result<(), Error>
pub fn push_from(&mut self, elem: T) -> Result<(), Error>
Prepends an element to the deque. Errors if the new collection length will not fit the confinement requirements.
source§impl<T: Hash + Eq, const MIN_LEN: usize, const MAX_LEN: usize> Confined<HashSet<T>, MIN_LEN, MAX_LEN>
impl<T: Hash + Eq, const MIN_LEN: usize, const MAX_LEN: usize> Confined<HashSet<T>, MIN_LEN, MAX_LEN>
source§impl<T: Ord, const MIN_LEN: usize, const MAX_LEN: usize> Confined<BTreeSet<T>, MIN_LEN, MAX_LEN>
impl<T: Ord, const MIN_LEN: usize, const MAX_LEN: usize> Confined<BTreeSet<T>, MIN_LEN, MAX_LEN>
source§impl<K: Hash + Eq, V, const MIN_LEN: usize, const MAX_LEN: usize> Confined<HashMap<K, V>, MIN_LEN, MAX_LEN>
impl<K: Hash + Eq, V, const MIN_LEN: usize, const MAX_LEN: usize> Confined<HashMap<K, V>, MIN_LEN, MAX_LEN>
sourcepub fn remove(&mut self, key: &K) -> Result<Option<V>, Error>
pub fn remove(&mut self, key: &K) -> Result<Option<V>, Error>
Removes an element from the map. Errors if the index exceeds the number of elements in the map, of if the new collection length will be less than the confinement requirement. Returns the removed value otherwise.
sourcepub fn into_keys(self) -> IntoKeys<K, V>
pub fn into_keys(self) -> IntoKeys<K, V>
Creates a consuming iterator visiting all the keys in arbitrary order.
The map cannot be used after calling this.
The iterator element type is K
.
sourcepub fn into_values(self) -> IntoValues<K, V>
pub fn into_values(self) -> IntoValues<K, V>
Creates a consuming iterator visiting all the values in arbitrary order.
The map cannot be used after calling this.
The iterator element type is V
.
source§impl<K: Ord + Hash, V, const MIN_LEN: usize, const MAX_LEN: usize> Confined<BTreeMap<K, V>, MIN_LEN, MAX_LEN>
impl<K: Ord + Hash, V, const MIN_LEN: usize, const MAX_LEN: usize> Confined<BTreeMap<K, V>, MIN_LEN, MAX_LEN>
sourcepub fn remove(&mut self, key: &K) -> Result<Option<V>, Error>
pub fn remove(&mut self, key: &K) -> Result<Option<V>, Error>
Removes an element from the map. Errors if the index exceeds the number of elements in the map, of if the new collection length will be less than the confinement requirement. Returns the removed value otherwise.
sourcepub fn into_keys(self) -> IntoKeys<K, V>
pub fn into_keys(self) -> IntoKeys<K, V>
Creates a consuming iterator visiting all the keys in arbitrary order.
The map cannot be used after calling this.
The iterator element type is K
.
sourcepub fn into_values(self) -> IntoValues<K, V>
pub fn into_values(self) -> IntoValues<K, V>
Creates a consuming iterator visiting all the values in arbitrary order.
The map cannot be used after calling this.
The iterator element type is V
.
Trait Implementations§
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> AsMut<[<C as Collection>::Item]> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> AsMut<[<C as Collection>::Item]> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> AsRef<[<C as Collection>::Item]> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> AsRef<[<C as Collection>::Item]> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Borrow<[<C as Collection>::Item]> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Borrow<[<C as Collection>::Item]> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> BorrowMut<[<C as Collection>::Item]> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> BorrowMut<[<C as Collection>::Item]> for Confined<C, MIN_LEN, MAX_LEN>
source§fn borrow_mut(&mut self) -> &mut [C::Item]
fn borrow_mut(&mut self) -> &mut [C::Item]
source§impl<C: Clone + Collection, const MIN_LEN: usize, const MAX_LEN: usize> Clone for Confined<C, MIN_LEN, MAX_LEN>
impl<C: Clone + Collection, const MIN_LEN: usize, const MAX_LEN: usize> Clone for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C: Debug + Collection, const MIN_LEN: usize, const MAX_LEN: usize> Debug for Confined<C, MIN_LEN, MAX_LEN>
impl<C: Debug + Collection, const MIN_LEN: usize, const MAX_LEN: usize> Debug for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MAX_LEN: usize> Default for Confined<C, ZERO, MAX_LEN>where
C: Default + Collection,
impl<C, const MAX_LEN: usize> Default for Confined<C, ZERO, MAX_LEN>where
C: Default + Collection,
source§impl<C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> Deref for Confined<C, MIN_LEN, MAX_LEN>
impl<C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> Deref for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Display for Confined<C, MIN_LEN, MAX_LEN>where
C: Display + Collection,
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Display for Confined<C, MIN_LEN, MAX_LEN>where
C: Display + Collection,
source§impl<const MIN_LEN: usize, const MAX_LEN: usize> FromHex for Confined<Vec<u8>, MIN_LEN, MAX_LEN>
impl<const MIN_LEN: usize, const MAX_LEN: usize> FromHex for Confined<Vec<u8>, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> FromStr for Confined<C, MIN_LEN, MAX_LEN>where
C: FromStr + Collection,
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> FromStr for Confined<C, MIN_LEN, MAX_LEN>where
C: FromStr + Collection,
source§impl<C: Hash + Collection, const MIN_LEN: usize, const MAX_LEN: usize> Hash for Confined<C, MIN_LEN, MAX_LEN>
impl<C: Hash + Collection, const MIN_LEN: usize, const MAX_LEN: usize> Hash for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<Range<usize>> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<Range<usize>> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<RangeFrom<usize>> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<RangeFrom<usize>> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<RangeFull> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<RangeFull> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<RangeInclusive<usize>> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<RangeInclusive<usize>> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<RangeTo<usize>> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<RangeTo<usize>> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<RangeToInclusive<usize>> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<RangeToInclusive<usize>> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<usize> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> Index<usize> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<Range<usize>> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<Range<usize>> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<RangeFrom<usize>> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<RangeFrom<usize>> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<RangeFull> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<RangeFull> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<RangeInclusive<usize>> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<RangeInclusive<usize>> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<RangeTo<usize>> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<RangeTo<usize>> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<RangeToInclusive<usize>> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<RangeToInclusive<usize>> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<usize> for Confined<C, MIN_LEN, MAX_LEN>
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IndexMut<usize> for Confined<C, MIN_LEN, MAX_LEN>
source§impl<'c, C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> IntoIterator for &'c Confined<C, MIN_LEN, MAX_LEN>where
&'c C: IntoIterator,
impl<'c, C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> IntoIterator for &'c Confined<C, MIN_LEN, MAX_LEN>where
&'c C: IntoIterator,
source§impl<'c, C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> IntoIterator for &'c mut Confined<C, MIN_LEN, MAX_LEN>where
&'c mut C: IntoIterator,
impl<'c, C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> IntoIterator for &'c mut Confined<C, MIN_LEN, MAX_LEN>where
&'c mut C: IntoIterator,
source§impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IntoIterator for Confined<C, MIN_LEN, MAX_LEN>where
C: IntoIterator + Collection,
impl<C, const MIN_LEN: usize, const MAX_LEN: usize> IntoIterator for Confined<C, MIN_LEN, MAX_LEN>where
C: IntoIterator + Collection,
source§impl<const MIN_LEN: usize, const MAX_LEN: usize> LowerHex for Confined<Vec<u8>, MIN_LEN, MAX_LEN>
impl<const MIN_LEN: usize, const MAX_LEN: usize> LowerHex for Confined<Vec<u8>, MIN_LEN, MAX_LEN>
source§impl<C: Ord + Collection, const MIN_LEN: usize, const MAX_LEN: usize> Ord for Confined<C, MIN_LEN, MAX_LEN>
impl<C: Ord + Collection, const MIN_LEN: usize, const MAX_LEN: usize> Ord for Confined<C, MIN_LEN, MAX_LEN>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<C: PartialEq + Collection, const MIN_LEN: usize, const MAX_LEN: usize> PartialEq for Confined<C, MIN_LEN, MAX_LEN>
impl<C: PartialEq + Collection, const MIN_LEN: usize, const MAX_LEN: usize> PartialEq for Confined<C, MIN_LEN, MAX_LEN>
source§impl<C: PartialOrd + Collection, const MIN_LEN: usize, const MAX_LEN: usize> PartialOrd for Confined<C, MIN_LEN, MAX_LEN>
impl<C: PartialOrd + Collection, const MIN_LEN: usize, const MAX_LEN: usize> PartialOrd for Confined<C, MIN_LEN, MAX_LEN>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<const MIN_LEN: usize, const MAX_LEN: usize> TryFrom<&str> for Confined<AsciiString, MIN_LEN, MAX_LEN>
impl<const MIN_LEN: usize, const MAX_LEN: usize> TryFrom<&str> for Confined<AsciiString, MIN_LEN, MAX_LEN>
source§impl<const MIN_LEN: usize, const MAX_LEN: usize> TryFrom<&str> for Confined<String, MIN_LEN, MAX_LEN>
impl<const MIN_LEN: usize, const MAX_LEN: usize> TryFrom<&str> for Confined<String, MIN_LEN, MAX_LEN>
source§impl<const MIN_LEN: usize, const MAX_LEN: usize> UpperHex for Confined<Vec<u8>, MIN_LEN, MAX_LEN>
impl<const MIN_LEN: usize, const MAX_LEN: usize> UpperHex for Confined<Vec<u8>, MIN_LEN, MAX_LEN>
source§impl<C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> Wrapper for Confined<C, MIN_LEN, MAX_LEN>
impl<C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> Wrapper for Confined<C, MIN_LEN, MAX_LEN>
source§impl<const MAX_LEN: usize> Write for Confined<Vec<u8>, ZERO, MAX_LEN>
impl<const MAX_LEN: usize> Write for Confined<Vec<u8>, ZERO, MAX_LEN>
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)