GameMods

Struct GameMods 

Source
pub struct GameMods { /* private fields */ }
Expand description

Combination of GameMods.

Implementations§

Source§

impl GameMods

Source

pub const fn new() -> Self

Returns empty mods i.e. “NoMod

Source

pub fn bits(&self) -> u32

Return the accumulated bit values of all contained mods.

Mods that don’t have bit values will be ignored. See https://github.com/ppy/osu-api/wiki#mods

§Example
let hdhrdtwu = mods!(Osu: HD HR DT WU);
assert_eq!(hdhrdtwu.bits(), 8 + 16 + 64);
Source

pub fn checked_bits(&self) -> Option<u32>

Return the accumulated bit values of all contained mods.

If any contained mod has no bit value None is returned. See https://github.com/ppy/osu-api/wiki#mods

§Example
let hdhrdt = mods!(Osu: HD HR DT);
assert_eq!(hdhrdt.checked_bits(), Some(8 + 16 + 64));

let hdhrdtwu = mods!(Osu: HD HR DT WU);
assert_eq!(hdhrdtwu.checked_bits(), None);
Source

pub fn is_empty(&self) -> bool

Returns true if no mods are contained.

§Example
use rosu_mods::{GameMod, GameMods};

let mut mods = GameMods::new();
assert!(mods.is_empty());

mods.insert(GameMod::HiddenOsu(Default::default()));
assert!(!mods.is_empty());
Source

pub fn len(&self) -> usize

Returns the amount of contained mods.

§Example
use rosu_mods::{GameMod, GameMods};

let hdhrdt = mods!(Catch: HD HR DT);
assert_eq!(hdhrdt.len(), 3);

let mut nm = GameMods::new();
assert_eq!(nm.len(), 0);
assert_eq!(nm.to_string(), "NM");
Source

pub fn insert(&mut self, gamemod: GameMod)

Add a GameMod

§Example
use rosu_mods::{GameMod, GameMods};

let mut mods = GameMods::new();
assert_eq!(mods.to_string(), "NM");

mods.insert(GameMod::TraceableOsu(Default::default()));
assert_eq!(mods.to_string(), "TC");

mods.insert(GameMod::HardRockOsu(Default::default()));
assert_eq!(mods.to_string(), "HRTC");
Source

pub fn contains(&self, gamemod: &GameMod) -> bool

Check whether a given GameMod is contained.

§Example
use rosu_mods::GameMod;

let hd = mods!(Taiko: HD);
assert!(hd.contains(&GameMod::HiddenTaiko(Default::default())));
assert!(!hd.contains(&GameMod::HiddenOsu(Default::default())));
Source

pub fn contains_intermode<M>(&self, gamemod: M) -> bool

Check whether a given GameModIntermode is contained.

§Example
use rosu_mods::GameModIntermode;

let hd = mods!(Taiko: HD);
assert!(hd.contains_intermode(GameModIntermode::Hidden));
assert!(!hd.contains_intermode(GameModIntermode::HardRock));
Source

pub fn contains_any<I, M>(&self, mods: I) -> bool
where I: IntoIterator<Item = M>, GameModIntermode: From<M>,

Check whether any of the given mods are contained.

Note that this method does not consider the mods’ modes so it could return true even if it’s a different mode.

§Example
use rosu_mods::mods;

let hd = mods!(Taiko: HD);

assert!(hd.contains_any(mods!(HD HR)));
assert!(!hd.contains_any(mods!(HR DT)));

// Careful: It returns `true` even if it's a different mode
assert!(hd.contains_any(mods!(Osu: HD)));
Source

pub fn contains_acronym(&self, acronym: Acronym) -> bool

Check whether a given Acronym is contained.

§Example
use rosu_mods::Acronym;

let mods = mods!(Osu: NF DT);

let nf = "NF".parse::<Acronym>().unwrap();
assert!(mods.contains_acronym(nf));

let hd = "HD".parse::<Acronym>().unwrap();
assert!(!mods.contains_acronym(hd));
Source

pub fn remove(&mut self, gamemod: &GameMod) -> bool

Remove a GameMod and return whether it was contained.

§Example
use rosu_mods::{GameMod, GameMods};

let mut mods: GameMods = mods!(Mania: DT MR);
#*/

assert!(mods.remove(&GameMod::MirrorMania(Default::default())));
assert_eq!(mods.to_string(), "DT");
assert!(!mods.remove(&GameMod::DoubleTimeCatch(Default::default())));
Source

pub fn remove_intermode<M>(&mut self, gamemod: M) -> bool

Remove a gamemod and return whether it was contained.

If the same gamemod is contained for multiple modes, only one of them will be removed.

§Example
use rosu_mods::{mods, GameModIntermode, GameMod, GameMods};

let mut mods: GameMods = [
    GameMod::HiddenOsu(Default::default()),
    GameMod::HiddenTaiko(Default::default()),
    GameMod::HardRockOsu(Default::default()),
].into_iter().collect();

assert_eq!(mods.to_string(), "HDHRHD");

assert!(mods.remove_intermode(GameModIntermode::Hidden));
assert_eq!(mods.to_string(), "HRHD");
assert!(!mods.remove_intermode(GameModIntermode::DoubleTime));
Source

pub fn remove_all<'m, I>(&mut self, mods: I)
where I: Iterator<Item = &'m GameMod>,

Remove all mods contained in the iterator.

§Example
use rosu_mods::{mods, GameMod, GameMods};

let mut mods: GameMods = mods!(Osu: HD HR WG DT BR);

mods.remove_all([
    GameMod::HiddenOsu(Default::default()),
    GameMod::EasyOsu(Default::default())
].iter());
assert_eq!(mods.to_string(), "DTHRBRWG");

mods.remove_all(mods!(Osu: NF WG).iter());
assert_eq!(mods.to_string(), "DTHRBR")
Source

pub fn remove_all_intermode<I, M>(&mut self, mods: I)
where I: IntoIterator<Item = M>, GameModIntermode: From<M>,

Remove all mods contained in the iterator.

If the same gamemod is contained for multiple modes, each occurence of the gamemod in the iterator will remove only one of the contained gamemods.

§Example
use rosu_mods::{mods, GameMod, GameMods};

 let mut mods: GameMods = [
   GameMod::HiddenOsu(Default::default()),
   GameMod::HardRockOsu(Default::default()),
   GameMod::HardRockCatch(Default::default()),
   GameMod::WiggleOsu(Default::default()),
   GameMod::DoubleTimeOsu(Default::default()),
   GameMod::BarrelRollOsu(Default::default()),
 ].into_iter().collect();

assert_eq!(mods.to_string(), "DTHDHRBRWGHR");
mods.remove_all_intermode(mods!(HD HR WG));
assert_eq!(mods.to_string(), "DTBRHR");
Source

pub fn intersection<'m>( &'m self, other: &'m GameMods, ) -> GameModsIntersection<'m>

Returns an iterator over all mods that appear in both GameMods.

§Example
use rosu_mods::GameMods;

let hd = mods!(Catch: HD);
let hdhr = mods!(Catch: HD HR);
let mut intersection = hd.intersection(&hdhr);

assert_eq!(intersection.next(), Some(&GameMod::HiddenCatch(Default::default())));
assert_eq!(intersection.next(), None);
Source

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

Check whether the two GameMods have any common mods.

§Example
use rosu_mods::GameMods;

let hd = mods!(Catch: HD);
let hr = mods!(Catch: HR);
assert!(!hd.intersects(&hr));

let hdhr = mods!(Catch: HD HR);
assert!(hd.intersects(&hdhr));
Source

pub fn clock_rate(&self) -> Option<f64>

The clock rate of the GameMods.

Returns None if any contained GameMod has no single clock rate.

§Example
use rosu_mods::GameMod;

let hd = mods!(Osu: HD);
assert_eq!(hd.clock_rate(), Some(1.0));

let mut hddt = hd;
hddt.insert(GameMod::DoubleTimeOsu(Default::default()));
assert_eq!(hddt.clock_rate(), Some(1.5));

let mut hddtwu = hddt;
hddtwu.insert(GameMod::WindUpOsu(Default::default()));
assert_eq!(hddtwu.clock_rate(), None);
Source

pub fn try_from_intermode( mods: &GameModsIntermode, mode: GameMode, ) -> Option<Self>

Tries to create GameMods from a GameModsIntermode.

Returns None if any contained GameModIntermode is unknown for the given GameMode.

§Example
use rosu_mods::{mods, GameMods, GameModsIntermode, GameMode};

let intermode: GameModsIntermode = mods!(DT FI);
let mods = GameMods::try_from_intermode(&intermode, GameMode::Mania).unwrap();

// The FadeIn mod doesn't exist in Taiko
assert!(GameMods::try_from_intermode(&intermode, GameMode::Taiko).is_none());
Source

pub fn from_intermode(mods: &GameModsIntermode, mode: GameMode) -> Self

Create GameMods from a GameModsIntermode.

Any contained GameModIntermode that’s unknown for the given GameMode will be replaced with GameModIntermode::Unknown.

§Example
use rosu_mods::{mods, GameMods, GameModsIntermode, GameMode};

let intermode: GameModsIntermode = mods!(DT FI);
let mods = GameMods::from_intermode(&intermode, GameMode::Mania);

// The FadeIn mod doesn't exist in Taiko
let dt = GameMods::from_intermode(&intermode, GameMode::Taiko);
Source

pub fn iter(&self) -> GameModsIter<'_>

Returns an iterator over all contained mods.

Note that the iterator will immediately yield None in case of “NoMod”.

Source

pub fn iter_mut(&mut self) -> GameModsIterMut<'_>

Returns an iterator that allows modifying each contained mod.

Note that the iterator will immediately yield None in case of “NoMod”.

Source

pub fn is_valid(&self) -> bool

Checks whether some contained mods exclude other contained mods.

§Example
use rosu_mods::GameMod;

let mut mods = mods!(Osu: EZ);
assert!(mods.is_valid());

mods.insert(GameMod::HardRockOsu(Default::default()));
assert!(!mods.is_valid());
Source

pub fn sanitize(&mut self)

Remove all mods that are excluded by other contained mods.

§Example
let mut mods = mods!(Osu: EZ HR);
assert_eq!(mods.to_string(), "EZHR");

mods.sanitize();
assert_eq!(mods.to_string(), "EZ");
Source

pub fn as_legacy(&self) -> GameModsLegacy

Source

pub fn try_as_legacy(&self) -> Option<GameModsLegacy>

Attempts to turns GameMods into GameModsLegacy.

Returns None if any contained GameMod does not have a bit value.

Trait Implementations§

Source§

impl Archive for GameMods

Available on crate feature rkyv only.
Source§

type Archived = <Vec<GameMod> as Archive>::Archived

The archived representation of this type. Read more
Source§

type Resolver = VecResolver

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
Source§

fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)

Creates the archived version of this value at the given position and writes it to the given output. Read more
Source§

const COPY_OPTIMIZATION: CopyOptimization<Self> = _

An optimization flag that allows the bytes of this type to be copied directly to a writer instead of calling serialize. Read more
Source§

impl Clone for GameMods

Source§

fn clone(&self) -> GameMods

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 GameMods

Source§

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

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

impl Default for GameMods

Source§

fn default() -> GameMods

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

impl<D: Fallible + ?Sized> Deserialize<GameMods, D> for ArchivedVec<Archived<GameMod>>

Available on crate feature rkyv only.
Source§

fn deserialize(&self, deserializer: &mut D) -> Result<GameMods, D::Error>

Deserializes using the given deserializer
Source§

impl Display for GameMods

Source§

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

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

impl Extend<GameMod> for GameMods

Source§

fn extend<T: IntoIterator<Item = GameMod>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<GameMod> for GameMods

Source§

fn from(gamemod: GameMod) -> Self

Converts to this type from the input type.
Source§

impl From<GameMods> for GameModsIntermode

Source§

fn from(mods: GameMods) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<GameMod> for GameMods

Source§

fn from_iter<T: IntoIterator<Item = GameMod>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a> IntoIterator for &'a GameMods

Source§

type Item = <GameModsIter<'a> as Iterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = GameModsIter<'a>

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<'a> IntoIterator for &'a mut GameMods

Source§

type Item = <GameModsIterMut<'a> as Iterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = GameModsIterMut<'a>

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 GameMods

Source§

fn into_iter(self) -> Self::IntoIter

Turns GameMods into an iterator over all contained mods.

Note that the iterator will immediately yield None in case of “NoMod”.

Source§

type Item = GameMod

The type of the elements being iterated over.
Source§

type IntoIter = IntoGameModsIter

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

impl PartialEq for GameMods

Source§

fn eq(&self, other: &GameMods) -> 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<S: Fallible<Error: Source> + Allocator + Writer + ?Sized> Serialize<S> for GameMods

Available on crate feature rkyv only.
Source§

fn serialize(&self, s: &mut S) -> Result<Self::Resolver, S::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.
Source§

impl Serialize for GameMods

Available on crate feature serde only.
Source§

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

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

impl StructuralPartialEq for GameMods

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> ArchiveUnsized for T
where T: Archive,

Source§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
Source§

fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata

Creates the archived version of the metadata for this value.
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Fallible + Writer + ?Sized,

Source§

fn serialize_unsized( &self, serializer: &mut S, ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived type.
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.