pub struct StrictSet<T, const MIN_LEN: u16 = 0>(_)
where
T: Eq + Ord + Debug + StrictEncode + StrictDecode;
Implementations§
source§impl<T> StrictSet<T, 0>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
impl<T> StrictSet<T, 0>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
source§impl<T, const MIN_LEN: u16> StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
impl<T, const MIN_LEN: u16> StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
Methods from Deref<Target = BTreeSet<T>>§
1.17.0 · sourcepub fn range<K, R>(&self, range: R) -> Range<'_, T>where
K: Ord + ?Sized,
T: Borrow<K> + Ord,
R: RangeBounds<K>,
pub fn range<K, R>(&self, range: R) -> Range<'_, T>where
K: Ord + ?Sized,
T: Borrow<K> + Ord,
R: RangeBounds<K>,
Constructs a double-ended iterator over a sub-range of elements in the set.
The simplest way is to use the range syntax min..max
, thus range(min..max)
will
yield elements from min (inclusive) to max (exclusive).
The range may also be entered as (Bound<T>, Bound<T>)
, so for example
range((Excluded(4), Included(10)))
will yield a left-exclusive, right-inclusive
range from 4 to 10.
Panics
Panics if range start > end
.
Panics if range start == end
and both bounds are Excluded
.
Examples
use std::collections::BTreeSet;
use std::ops::Bound::Included;
let mut set = BTreeSet::new();
set.insert(3);
set.insert(5);
set.insert(8);
for &elem in set.range((Included(&4), Included(&8))) {
println!("{elem}");
}
assert_eq!(Some(&5), set.range(4..).next());
1.0.0 · sourcepub fn difference<'a>(
&'a self,
other: &'a BTreeSet<T, A>
) -> Difference<'a, T, A>where
T: Ord,
pub fn difference<'a>(
&'a self,
other: &'a BTreeSet<T, A>
) -> Difference<'a, T, A>where
T: Ord,
Visits the elements representing the difference,
i.e., the elements that are in self
but not in other
,
in ascending order.
Examples
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
let mut b = BTreeSet::new();
b.insert(2);
b.insert(3);
let diff: Vec<_> = a.difference(&b).cloned().collect();
assert_eq!(diff, [1]);
1.0.0 · sourcepub fn symmetric_difference<'a>(
&'a self,
other: &'a BTreeSet<T, A>
) -> SymmetricDifference<'a, T>where
T: Ord,
pub fn symmetric_difference<'a>(
&'a self,
other: &'a BTreeSet<T, A>
) -> SymmetricDifference<'a, T>where
T: Ord,
Visits the elements representing the symmetric difference,
i.e., the elements that are in self
or in other
but not in both,
in ascending order.
Examples
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
let mut b = BTreeSet::new();
b.insert(2);
b.insert(3);
let sym_diff: Vec<_> = a.symmetric_difference(&b).cloned().collect();
assert_eq!(sym_diff, [1, 3]);
1.0.0 · sourcepub fn intersection<'a>(
&'a self,
other: &'a BTreeSet<T, A>
) -> Intersection<'a, T, A>where
T: Ord,
pub fn intersection<'a>(
&'a self,
other: &'a BTreeSet<T, A>
) -> Intersection<'a, T, A>where
T: Ord,
Visits the elements representing the intersection,
i.e., the elements that are both in self
and other
,
in ascending order.
Examples
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
let mut b = BTreeSet::new();
b.insert(2);
b.insert(3);
let intersection: Vec<_> = a.intersection(&b).cloned().collect();
assert_eq!(intersection, [2]);
1.0.0 · sourcepub fn union<'a>(&'a self, other: &'a BTreeSet<T, A>) -> Union<'a, T>where
T: Ord,
pub fn union<'a>(&'a self, other: &'a BTreeSet<T, A>) -> Union<'a, T>where
T: Ord,
Visits the elements representing the union,
i.e., all the elements in self
or other
, without duplicates,
in ascending order.
Examples
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
let mut b = BTreeSet::new();
b.insert(2);
let union: Vec<_> = a.union(&b).cloned().collect();
assert_eq!(union, [1, 2]);
1.0.0 · sourcepub fn contains<Q>(&self, value: &Q) -> boolwhere
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn contains<Q>(&self, value: &Q) -> boolwhere
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns true
if the set contains an element equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form must match the ordering on the element type.
Examples
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.contains(&1), true);
assert_eq!(set.contains(&4), false);
1.9.0 · sourcepub fn get<Q>(&self, value: &Q) -> Option<&T>where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn get<Q>(&self, value: &Q) -> Option<&T>where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns a reference to the element in the set, if any, that is equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form must match the ordering on the element type.
Examples
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.get(&2), Some(&2));
assert_eq!(set.get(&4), None);
1.0.0 · sourcepub fn is_disjoint(&self, other: &BTreeSet<T, A>) -> boolwhere
T: Ord,
pub fn is_disjoint(&self, other: &BTreeSet<T, A>) -> boolwhere
T: Ord,
Returns true
if self
has no elements in common with other
.
This is equivalent to checking for an empty intersection.
Examples
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let mut b = BTreeSet::new();
assert_eq!(a.is_disjoint(&b), true);
b.insert(4);
assert_eq!(a.is_disjoint(&b), true);
b.insert(1);
assert_eq!(a.is_disjoint(&b), false);
1.0.0 · sourcepub fn is_subset(&self, other: &BTreeSet<T, A>) -> boolwhere
T: Ord,
pub fn is_subset(&self, other: &BTreeSet<T, A>) -> boolwhere
T: Ord,
Returns true
if the set is a subset of another,
i.e., other
contains at least all the elements in self
.
Examples
use std::collections::BTreeSet;
let sup = BTreeSet::from([1, 2, 3]);
let mut set = BTreeSet::new();
assert_eq!(set.is_subset(&sup), true);
set.insert(2);
assert_eq!(set.is_subset(&sup), true);
set.insert(4);
assert_eq!(set.is_subset(&sup), false);
1.0.0 · sourcepub fn is_superset(&self, other: &BTreeSet<T, A>) -> boolwhere
T: Ord,
pub fn is_superset(&self, other: &BTreeSet<T, A>) -> boolwhere
T: Ord,
Returns true
if the set is a superset of another,
i.e., self
contains at least all the elements in other
.
Examples
use std::collections::BTreeSet;
let sub = BTreeSet::from([1, 2]);
let mut set = BTreeSet::new();
assert_eq!(set.is_superset(&sub), false);
set.insert(0);
set.insert(1);
assert_eq!(set.is_superset(&sub), false);
set.insert(2);
assert_eq!(set.is_superset(&sub), true);
1.66.0 · sourcepub fn first(&self) -> Option<&T>where
T: Ord,
pub fn first(&self) -> Option<&T>where
T: Ord,
Returns a reference to the first element in the set, if any. This element is always the minimum of all elements in the set.
Examples
Basic usage:
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
assert_eq!(set.first(), None);
set.insert(1);
assert_eq!(set.first(), Some(&1));
set.insert(2);
assert_eq!(set.first(), Some(&1));
1.66.0 · sourcepub fn last(&self) -> Option<&T>where
T: Ord,
pub fn last(&self) -> Option<&T>where
T: Ord,
Returns a reference to the last element in the set, if any. This element is always the maximum of all elements in the set.
Examples
Basic usage:
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
assert_eq!(set.last(), None);
set.insert(1);
assert_eq!(set.last(), Some(&1));
set.insert(2);
assert_eq!(set.last(), Some(&2));
1.0.0 · sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Gets an iterator that visits the elements in the BTreeSet
in ascending
order.
Examples
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
let mut set_iter = set.iter();
assert_eq!(set_iter.next(), Some(&1));
assert_eq!(set_iter.next(), Some(&2));
assert_eq!(set_iter.next(), Some(&3));
assert_eq!(set_iter.next(), None);
Values returned by the iterator are returned in ascending order:
use std::collections::BTreeSet;
let set = BTreeSet::from([3, 1, 2]);
let mut set_iter = set.iter();
assert_eq!(set_iter.next(), Some(&1));
assert_eq!(set_iter.next(), Some(&2));
assert_eq!(set_iter.next(), Some(&3));
assert_eq!(set_iter.next(), None);
Trait Implementations§
source§impl<T, const MIN_LEN: u16> Clone for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + Clone,
impl<T, const MIN_LEN: u16> Clone for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + Clone,
source§impl<T, const MIN_LEN: u16> Debug for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + Debug,
impl<T, const MIN_LEN: u16> Debug for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + Debug,
source§impl<T> Default for StrictSet<T, 0>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
impl<T> Default for StrictSet<T, 0>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
source§impl<T, const MIN_LEN: u16> Deref for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
impl<T, const MIN_LEN: u16> Deref for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
source§impl From<StrictSet<PrimitiveType, 2>> for UnionType
impl From<StrictSet<PrimitiveType, 2>> for UnionType
source§fn from(v: StrictSet<PrimitiveType, 2>) -> Self
fn from(v: StrictSet<PrimitiveType, 2>) -> Self
source§impl<T, const MIN_LEN: u16> Hash for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + Hash,
impl<T, const MIN_LEN: u16> Hash for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + Hash,
source§impl<'me, T, const MIN_LEN: u16> IntoIterator for &'me StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
impl<'me, T, const MIN_LEN: u16> IntoIterator for &'me StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
source§impl<T, const MIN_LEN: u16> Ord for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + Ord,
impl<T, const MIN_LEN: u16> Ord for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + Ord,
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<T, const MIN_LEN: u16> PartialEq<StrictSet<T, MIN_LEN>> for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + PartialEq,
impl<T, const MIN_LEN: u16> PartialEq<StrictSet<T, MIN_LEN>> for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + PartialEq,
source§impl<T, const MIN_LEN: u16> PartialOrd<StrictSet<T, MIN_LEN>> for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + PartialOrd,
impl<T, const MIN_LEN: u16> PartialOrd<StrictSet<T, MIN_LEN>> for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode + PartialOrd,
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<T, const MIN_LEN: u16> StrictDecode for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
impl<T, const MIN_LEN: u16> StrictDecode for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
source§fn strict_decode<D: Read>(d: D) -> Result<Self, Error>
fn strict_decode<D: Read>(d: D) -> Result<Self, Error>
std::io::Read
instance; must either
construct an instance or return implementation-specific error type.source§fn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>
fn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>
StrictDecode::strict_decode
. If there are some data remains in the
buffer once deserialization is completed, fails with
Error::DataNotEntirelyConsumed
. Use io::Cursor
over the buffer and
StrictDecode::strict_decode
to avoid such failures.source§fn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>
fn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>
path
and reconstructs object from it. Fails
with Error::DataNotEntirelyConsumed
if file contains remaining
data after the object reconstruction.source§impl<T, const MIN_LEN: u16> StrictEncode for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
impl<T, const MIN_LEN: u16> StrictEncode for StrictSet<T, MIN_LEN>where
T: Eq + Ord + Debug + StrictEncode + StrictDecode,
source§fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>
fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>
std::io::Write
instance; must return result
with either amount of bytes encoded – or implementation-specific
error type.source§fn strict_serialize(&self) -> Result<Vec<u8, Global>, Error>
fn strict_serialize(&self) -> Result<Vec<u8, Global>, Error>
StrictEncode::strict_encode
function