StrangePartSet

Struct StrangePartSet 

Source
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

Source

pub fn new() -> Self

Creates a set for strange parts.

§Examples
use tf2_enum::StrangePartSet;
 
let strange_parts = StrangePartSet::new();
Source

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);
Source

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);
Source

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

Source§

const MAX_COUNT: usize = 3usize

Max number of items.

Source§

const NONE: Self

An empty StrangePartSet.

Source§

type Item = StrangePart

The item type.

Source§

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

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

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>

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

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>

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>]

Returns the inner storage as a slice.

Source§

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>

Same as 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

Adds an item to the first available slot. Replaces the last item in the set if the set is full. Returns false if the set already contains the value.
Source§

fn get(&self, index: usize) -> Option<&Self::Item>

Gets an item from the set by index.
Source§

fn len(&self) -> usize

Returns the number of elements in the set.
Source§

fn contains(&self, item: &Self::Item) -> bool

Returns true if the set contains the given item.
Source§

fn is_empty(&self) -> bool

Returns true if the set is empty.
Source§

fn is_full(&self) -> bool

Returns true if the set is full, i.e., it contains the maximum number of elements.
Source§

fn capacity(&self) -> usize

Gets the capacity of the set.
Source§

fn first(&self) -> Option<&Self::Item>

Gets the first item in the set.
Source§

fn last(&self) -> Option<&Self::Item>

Gets the last item in the set.
Source§

fn difference(&self, other: &Self) -> Self

Returns the items that are in self but not in other.
Source§

fn intersection(&self, other: &Self) -> Self

Returns the items that are both in self and other.
Source§

fn is_disjoint(&self, other: &Self) -> bool

Returns 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

Returns true if the set is a subset of another, i.e., other contains at least all the values in self.
Source§

fn is_superset(&self, other: &Self) -> bool

Returns true if the set is a superset of another, i.e., self contains at least all the values in other.
Source§

fn iter(&self) -> impl Iterator<Item = &Self::Item>

Returns an iterator over the set.
Source§

fn iter_mut(&mut self) -> impl Iterator<Item = &mut Self::Item>

Returns a mutable iterator over the set.
Source§

fn retain<F>(&mut self, f: F)
where F: FnMut(&Self::Item) -> bool,

Retains only the items specified by the predicate.
Source§

fn extend<I: IntoIterator<Item = Self::Item>>(&mut self, iter: I)

Extends items from an iterator into the set.
Source§

impl BitAnd for &StrangePartSet

Source§

type Output = StrangePartSet

The resulting type after applying the & operator.
Source§

fn bitand(self, other: &StrangePartSet) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd for StrangePartSet

Source§

type Output = StrangePartSet

The resulting type after applying the & operator.
Source§

fn bitand(self, other: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl Clone for StrangePartSet

Source§

fn clone(&self) -> StrangePartSet

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StrangePartSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StrangePartSet

Source§

fn default() -> StrangePartSet

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for StrangePartSet

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for StrangePartSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&StrangePartSet> for Vec<StrangePart>

Source§

fn from(spell_set: &StrangePartSet) -> Self

Converts to this type from the input type.
Source§

impl From<[Option<StrangePart>; 3]> for StrangePartSet

Source§

fn from(inner: [Option<StrangePart>; 3]) -> Self

Converts to this type from the input type.
Source§

impl From<StrangePartSet> for Vec<StrangePart>

Source§

fn from(spell_set: StrangePartSet) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromIterator<&'a StrangePart> for StrangePartSet

Source§

fn from_iter<I: IntoIterator<Item = &'a StrangePart>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a> FromIterator<Option<&'a StrangePart>> for StrangePartSet

Source§

fn from_iter<I: IntoIterator<Item = Option<&'a StrangePart>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Option<StrangePart>> for StrangePartSet

Source§

fn from_iter<I: IntoIterator<Item = Option<StrangePart>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<StrangePart> for StrangePartSet

Source§

fn from_iter<I: IntoIterator<Item = StrangePart>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for StrangePartSet

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoIterator for &StrangePartSet

Source§

type Item = StrangePart

The type of the elements being iterated over.
Source§

type IntoIter = StrangePartSetIterator

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for StrangePartSet

Source§

type Item = StrangePart

The type of the elements being iterated over.
Source§

type IntoIter = StrangePartSetIterator

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for StrangePartSet

Source§

fn cmp(&self, other: &StrangePartSet) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for StrangePartSet

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for StrangePartSet

Source§

fn partial_cmp(&self, other: &StrangePartSet) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for StrangePartSet

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub for &StrangePartSet

Source§

type Output = StrangePartSet

The resulting type after applying the - operator.
Source§

fn sub(self, other: &StrangePartSet) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for StrangePartSet

Source§

type Output = StrangePartSet

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Copy for StrangePartSet

Source§

impl Eq for StrangePartSet

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,