allow conversion of &mut Beatmap

This commit is contained in:
MaxOhn
2024-03-02 18:19:53 +01:00
parent 3681ff725b
commit 88f70164b7
2 changed files with 44 additions and 0 deletions
+24
View File
@@ -130,6 +130,30 @@ impl<'a, M: IGameMode> Converted<'a, M> {
Self::try_from_ref(map).expect(INCOMPATIBLE_MODES)
}
/// Attempt to convert a [`&mut Beatmap`] to the specified mode.
///
/// If the conversion is incompatible, `None` is returned.
///
/// [`&mut Beatmap`]: Beatmap
pub fn try_from_mut(map: &'a mut Beatmap) -> Option<Self> {
match M::try_convert(map) {
ConvertStatus::Conversion => Some(Self::new(Cow::Borrowed(map))),
ConvertStatus::Noop => Some(Self::new(Cow::Borrowed(map))),
ConvertStatus::Incompatible => None,
}
}
/// Convert a [`&mut Beatmap`] to the specified mode.
///
/// # Panics
///
/// Panics if the conversion is incompatible.
///
/// [`&mut Beatmap`]: Beatmap
pub fn unchecked_from_mut(map: &'a mut Beatmap) -> Self {
Self::try_from_mut(map).expect(INCOMPATIBLE_MODES)
}
/// Attempt to convert a [`Converted`] from mode `M` to mode `N`.
///
/// If the conversion is incompatible the [`Converted`] will be returned
+20
View File
@@ -131,6 +131,26 @@ impl Beatmap {
Converted::unchecked_from_ref(self)
}
/// Attempt to convert a [`&mut Beatmap`] to the specified mode.
///
/// If the conversion is incompatible, `None` is returned.
///
/// [`&mut Beatmap`]: Beatmap
pub fn try_as_converted_mut<M: IGameMode>(&mut self) -> Option<Converted<'_, M>> {
Converted::try_from_mut(self)
}
/// Convert a [`&mut Beatmap`] to the specified mode.
///
/// # Panics
///
/// Panics if the conversion is incompatible.
///
/// [`&mut Beatmap`]: Beatmap
pub fn unchecked_as_converted_mut<M: IGameMode>(&mut self) -> Converted<'_, M> {
Converted::unchecked_from_mut(self)
}
/// Attempt to convert a [`Beatmap`] to the specified mode.
///
/// If the conversion is incompatible the [`Beatmap`] will be returned