pub struct StrangePartSet { /* private fields */ }
Expand description
Contains up to 3 strange parts. Although the underlying data structure is an array, this
structure behaves like a set. Most methods mimic those of
HashSet
, with a few differences.
This struct solves the following problems:
- An item can only hold up to 3 strange parts.
- An item cannot have duplicate strange parts.
- Comparing strange parts for equality is order-agnostic.
- Hashing is order-agnostic.
- The type is
Copy
, allowing for cheap and easy duplication.
Most methods are implemented under the AttributeSet
trait, make sure to import it to make
use of them.
§Examples
use tf2_enum::{StrangePartSet, StrangePart, AttributeSet};
// Create a set for strange parts with two strange parts.
let mut strange_parts = StrangePartSet::double(
StrangePart::CriticalKills,
StrangePart::DamageDealt,
);
// Check that strange parts contains Damage Dealt.
assert!(strange_parts.contains(&StrangePart::DamageDealt));
assert_eq!(strange_parts.len(), 2);
// Add a strange part.
strange_parts.insert(StrangePart::EngineersKilled);
assert_eq!(strange_parts.len(), 3);
// If a strange part is added when strange parts are full, the insert will fail.
assert!(!strange_parts.insert(StrangePart::MedicsKilled));
assert!(!strange_parts.contains(&StrangePart::MedicsKilled));
// Iterate over strange parts.
for strange_part in strange_parts {
println!("{}", strange_part.strange_part_name());
}
Implementations§
Source§impl StrangePartSet
impl StrangePartSet
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a set for strange parts.
§Examples
use tf2_enum::StrangePartSet;
let strange_parts = StrangePartSet::new();
Sourcepub fn single(strange_part: StrangePart) -> Self
pub fn single(strange_part: StrangePart) -> Self
Creates a set for strange parts with one strange part.
§Examples
use tf2_enum::{StrangePartSet, StrangePart, AttributeSet};
let strange_parts = StrangePartSet::single(
StrangePart::DamageDealt,
);
assert_eq!(strange_parts.len(), 1);
Sourcepub fn double(strange_part1: StrangePart, strange_part2: StrangePart) -> Self
pub fn double(strange_part1: StrangePart, strange_part2: StrangePart) -> Self
Creates a set for strange parts with two strange parts.
If the same strange part is added multiple times, only one will be kept.
§Examples
use tf2_enum::{StrangePartSet, StrangePart, AttributeSet};
let strange_parts = StrangePartSet::double(
StrangePart::DamageDealt,
StrangePart::CriticalKills,
);
assert_eq!(strange_parts.len(), 2);
Sourcepub fn triple(
strange_part1: StrangePart,
strange_part2: StrangePart,
strange_part3: StrangePart,
) -> Self
pub fn triple( strange_part1: StrangePart, strange_part2: StrangePart, strange_part3: StrangePart, ) -> Self
Creates a set for strange parts with two strange parts.
If the same strange part is added multiple times, only one will be kept.
§Examples
use tf2_enum::{StrangePartSet, StrangePart, AttributeSet};
let strange_parts = StrangePartSet::triple(
StrangePart::DamageDealt,
StrangePart::CriticalKills,
StrangePart::EngineersKilled,
);
assert_eq!(strange_parts.len(), 3);
Trait Implementations§
Source§impl AttributeSet for StrangePartSet
impl AttributeSet for StrangePartSet
Source§const NONE: Self
const NONE: Self
An empty StrangePartSet
.
Source§type Item = StrangePart
type Item = StrangePart
The item type.
Source§fn clear(&mut self)
fn clear(&mut self)
Clears the set, removing all strange parts.
§Examples
use tf2_enum::{StrangePartSet, StrangePart, AttributeSet};
let mut strange_parts = StrangePartSet::double(
StrangePart::CriticalKills,
StrangePart::DamageDealt,
);
strange_parts.clear();
assert_eq!(strange_parts.len(), 0);
Source§fn insert(&mut self, strange_part: StrangePart) -> bool
fn insert(&mut self, strange_part: StrangePart) -> bool
Adds a strange part to the first available slot. If no slots are available, the new strange part will be ignored.
Returns false
if:
- The strange part is already in the set.
- The set is full.
§Examples
use tf2_enum::{StrangePartSet, StrangePart, AttributeSet};
let mut strange_parts = StrangePartSet::double(
StrangePart::CriticalKills,
StrangePart::DamageDealt,
);
assert_eq!(strange_parts.len(), 2);
strange_parts.insert(StrangePart::EngineersKilled);
assert_eq!(strange_parts.len(), 3);
// Strange parts are full.
assert!(!strange_parts.insert(StrangePart::MedicsKilled));
Source§fn remove(&mut self, strange_part: &StrangePart) -> bool
fn remove(&mut self, strange_part: &StrangePart) -> bool
Removes a strange part.
§Examples
use tf2_enum::{StrangePartSet, StrangePart, AttributeSet};
let mut strange_parts = StrangePartSet::single(StrangePart::CriticalKills);
assert!(strange_parts.remove(&StrangePart::CriticalKills));
assert!(!strange_parts.contains(&StrangePart::CriticalKills));
Source§fn take(&mut self, strange_part: &StrangePart) -> Option<StrangePart>
fn take(&mut self, strange_part: &StrangePart) -> Option<StrangePart>
Removes and returns the strange part in the set, if any, that is equal to the given one.
Source§fn replace(
&mut self,
strange_part: &StrangePart,
new_strange_part: StrangePart,
) -> bool
fn replace( &mut self, strange_part: &StrangePart, new_strange_part: StrangePart, ) -> bool
Replaces a strange part in the set with a new strange part. false
if the strange part was
not present.
Source§fn iter_attributes(&self) -> impl Iterator<Item = ItemAttribute>
fn iter_attributes(&self) -> impl Iterator<Item = ItemAttribute>
Converts each element to an ItemAttribute
. This doesn’t include attributes for the
score counters, only the score types.
Source§fn as_slice(&self) -> &[Option<StrangePart>]
fn as_slice(&self) -> &[Option<StrangePart>]
Returns the inner storage as a slice.
Source§fn as_mut_slice(&mut self) -> &mut [Option<StrangePart>]
fn as_mut_slice(&mut self) -> &mut [Option<StrangePart>]
Returns the inner storage as a mutable slice.
Source§fn try_insert(&mut self, strange_part: StrangePart) -> Result<(), InsertError>
fn try_insert(&mut self, strange_part: StrangePart) -> Result<(), InsertError>
insert
, but returns a std::result::Result
with descriptive error to identify
why the insert failed.Source§fn insert_or_replace_last(&mut self, strange_part: StrangePart) -> bool
fn insert_or_replace_last(&mut self, strange_part: StrangePart) -> bool
false
if the set already contains the value.Source§fn contains(&self, item: &Self::Item) -> bool
fn contains(&self, item: &Self::Item) -> bool
Source§fn is_full(&self) -> bool
fn is_full(&self) -> bool
Source§fn difference(&self, other: &Self) -> Self
fn difference(&self, other: &Self) -> Self
self
but not in other
.Source§fn intersection(&self, other: &Self) -> Self
fn intersection(&self, other: &Self) -> Self
self
and other
.Source§fn is_disjoint(&self, other: &Self) -> bool
fn is_disjoint(&self, other: &Self) -> bool
true
if self
has no items in common with other
. This is equivalent to
checking for an empty intersection.Source§fn is_subset(&self, other: &Self) -> bool
fn is_subset(&self, other: &Self) -> bool
Source§fn is_superset(&self, other: &Self) -> bool
fn is_superset(&self, other: &Self) -> bool
Source§fn iter_mut(&mut self) -> impl Iterator<Item = &mut Self::Item>
fn iter_mut(&mut self) -> impl Iterator<Item = &mut Self::Item>
Source§fn extend<I: IntoIterator<Item = Self::Item>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Self::Item>>(&mut self, iter: I)
Source§impl BitAnd for &StrangePartSet
impl BitAnd for &StrangePartSet
Source§type Output = StrangePartSet
type Output = StrangePartSet
&
operator.Source§impl BitAnd for StrangePartSet
impl BitAnd for StrangePartSet
Source§impl Clone for StrangePartSet
impl Clone for StrangePartSet
Source§fn clone(&self) -> StrangePartSet
fn clone(&self) -> StrangePartSet
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for StrangePartSet
impl Debug for StrangePartSet
Source§impl Default for StrangePartSet
impl Default for StrangePartSet
Source§fn default() -> StrangePartSet
fn default() -> StrangePartSet
Source§impl<'de> Deserialize<'de> for StrangePartSet
impl<'de> Deserialize<'de> for StrangePartSet
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for StrangePartSet
impl Display for StrangePartSet
Source§impl From<&StrangePartSet> for Vec<StrangePart>
impl From<&StrangePartSet> for Vec<StrangePart>
Source§fn from(spell_set: &StrangePartSet) -> Self
fn from(spell_set: &StrangePartSet) -> Self
Source§impl From<[Option<StrangePart>; 3]> for StrangePartSet
impl From<[Option<StrangePart>; 3]> for StrangePartSet
Source§impl From<StrangePartSet> for Vec<StrangePart>
impl From<StrangePartSet> for Vec<StrangePart>
Source§fn from(spell_set: StrangePartSet) -> Self
fn from(spell_set: StrangePartSet) -> Self
Source§impl<'a> FromIterator<&'a StrangePart> for StrangePartSet
impl<'a> FromIterator<&'a StrangePart> for StrangePartSet
Source§fn from_iter<I: IntoIterator<Item = &'a StrangePart>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = &'a StrangePart>>(iter: I) -> Self
Source§impl<'a> FromIterator<Option<&'a StrangePart>> for StrangePartSet
impl<'a> FromIterator<Option<&'a StrangePart>> for StrangePartSet
Source§fn from_iter<I: IntoIterator<Item = Option<&'a StrangePart>>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = Option<&'a StrangePart>>>(iter: I) -> Self
Source§impl FromIterator<Option<StrangePart>> for StrangePartSet
impl FromIterator<Option<StrangePart>> for StrangePartSet
Source§fn from_iter<I: IntoIterator<Item = Option<StrangePart>>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = Option<StrangePart>>>(iter: I) -> Self
Source§impl FromIterator<StrangePart> for StrangePartSet
impl FromIterator<StrangePart> for StrangePartSet
Source§fn from_iter<I: IntoIterator<Item = StrangePart>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = StrangePart>>(iter: I) -> Self
Source§impl Hash for StrangePartSet
impl Hash for StrangePartSet
Source§impl IntoIterator for &StrangePartSet
impl IntoIterator for &StrangePartSet
Source§impl IntoIterator for StrangePartSet
impl IntoIterator for StrangePartSet
Source§impl Ord for StrangePartSet
impl Ord for StrangePartSet
Source§fn cmp(&self, other: &StrangePartSet) -> Ordering
fn cmp(&self, other: &StrangePartSet) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for StrangePartSet
impl PartialEq for StrangePartSet
Source§impl PartialOrd for StrangePartSet
impl PartialOrd for StrangePartSet
Source§impl Serialize for StrangePartSet
impl Serialize for StrangePartSet
Source§impl Sub for &StrangePartSet
impl Sub for &StrangePartSet
Source§type Output = StrangePartSet
type Output = StrangePartSet
-
operator.