pub struct Set<T> { /* private fields */ }
Expand description
Implementations§
Source§impl<T> Set<T>
impl<T> Set<T>
Source§impl<T> Set<T>
impl<T> Set<T>
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted in the Set
.
Sourcepub fn contains<Q>(&self, value: &Q) -> bool
pub fn contains<Q>(&self, value: &Q) -> bool
Returns true if the Set
contains an element equal to the value
.
Sourcepub fn get<Q>(&self, value: &Q) -> Option<&T>
pub fn get<Q>(&self, value: &Q) -> Option<&T>
Returns a reference to the element in the Set
, if any, that is equal to the value
.
Sourcepub fn insert(&mut self, value: T) -> bool
pub fn insert(&mut self, value: T) -> bool
Adds value
to the Set
.
Returns whether the value was newly inserted:
- Returns
true
if the set did not previously contain an equal value. - Returns
false
otherwise and the entry is not updated.
Sourcepub fn remove<Q>(&mut self, value: &Q) -> bool
pub fn remove<Q>(&mut self, value: &Q) -> bool
If the set contains an element equal to the value, removes it from the Set
and drops it.
Returns true
if such an element was present, otherwise false
.
Sourcepub fn take<Q>(&mut self, value: &Q) -> Option<T>
pub fn take<Q>(&mut self, value: &Q) -> Option<T>
Removes and returns 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.
Sourcepub fn replace(&mut self, value: T) -> Option<T>
pub fn replace(&mut self, value: T) -> Option<T>
Adds a value to the Set
, replacing the existing value, if any, that is equal to the given
one. Returns the replaced value.
Sourcepub fn is_disjoint(&self, other: &Set<T>) -> bool
pub fn is_disjoint(&self, other: &Set<T>) -> bool
Returns true
if self
has no elements in common with other
.
This is equivalent to checking for an empty intersection.
Sourcepub fn is_subset(&self, other: &Set<T>) -> bool
pub fn is_subset(&self, other: &Set<T>) -> bool
Returns true
if the Set
is a subset of another,
i.e., other
contains at least all the values in self
.
Sourcepub fn is_superset(&self, other: &Set<T>) -> bool
pub fn is_superset(&self, other: &Set<T>) -> bool
Returns true
if the Set
is a superset of another,
i.e., self
contains at least all the values in other
.
Sourcepub fn difference<'a>(&'a self, other: &'a Set<T>) -> Difference<'a, T> ⓘ
pub fn difference<'a>(&'a self, other: &'a Set<T>) -> Difference<'a, T> ⓘ
Visits the values representing the difference,
i.e., the values that are in self
but not in other
.
Sourcepub fn symmetric_difference<'a>(
&'a self,
other: &'a Set<T>,
) -> SymmetricDifference<'a, T> ⓘ
pub fn symmetric_difference<'a>( &'a self, other: &'a Set<T>, ) -> SymmetricDifference<'a, T> ⓘ
Visits the values representing the symmetric difference,
i.e., the values that are in self
or in other
but not in both.
Sourcepub fn intersection<'a>(&'a self, other: &'a Set<T>) -> Intersection<'a, T> ⓘ
pub fn intersection<'a>(&'a self, other: &'a Set<T>) -> Intersection<'a, T> ⓘ
Visits the values representing the intersection,
i.e., the values that are both in self
and other
.
When an equal element is present in self
and other
then the resulting Intersection
may yield references to
one or the other. This can be relevant if T
contains fields which
are not compared by its Eq
implementation, and may hold different
value between the two equal copies of T
in the two sets.
Trait Implementations§
Source§impl<'a, T> Deserialize<'a> for Set<T>
impl<'a, T> Deserialize<'a> for Set<T>
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Set<T>, <D as Deserializer<'a>>::Error>where
D: Deserializer<'a>,
fn deserialize<D>(
deserializer: D,
) -> Result<Set<T>, <D as Deserializer<'a>>::Error>where
D: Deserializer<'a>,
Source§impl<'a, T> Extend<&'a T> for Set<T>
impl<'a, T> Extend<&'a T> for Set<T>
Source§fn extend<Iter>(&mut self, iter: Iter)where
Iter: IntoIterator<Item = &'a T>,
fn extend<Iter>(&mut self, iter: Iter)where
Iter: IntoIterator<Item = &'a T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<T> Extend<T> for Set<T>
impl<T> Extend<T> for Set<T>
Source§fn extend<Iter>(&mut self, iter: Iter)where
Iter: IntoIterator<Item = T>,
fn extend<Iter>(&mut self, iter: Iter)where
Iter: IntoIterator<Item = T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<T> FromIterator<T> for Set<T>
impl<T> FromIterator<T> for Set<T>
Source§impl<'a, T> IntoIterator for &'a Set<T>
impl<'a, T> IntoIterator for &'a Set<T>
Source§impl<T> IntoIterator for Set<T>
impl<T> IntoIterator for Set<T>
Source§impl<T> Serialize for Set<T>
impl<T> Serialize for Set<T>
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl<T> Eq for Set<T>
Auto Trait Implementations§
impl<T> Freeze for Set<T>
impl<T> RefUnwindSafe for Set<T>where
T: RefUnwindSafe,
impl<T> Send for Set<T>where
T: Send,
impl<T> Sync for Set<T>where
T: Sync,
impl<T> Unpin for Set<T>where
T: Unpin,
impl<T> UnwindSafe for Set<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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.