allow conversion of &mut Beatmap
This commit is contained in:
@@ -130,6 +130,30 @@ impl<'a, M: IGameMode> Converted<'a, M> {
|
|||||||
Self::try_from_ref(map).expect(INCOMPATIBLE_MODES)
|
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`.
|
/// Attempt to convert a [`Converted`] from mode `M` to mode `N`.
|
||||||
///
|
///
|
||||||
/// If the conversion is incompatible the [`Converted`] will be returned
|
/// If the conversion is incompatible the [`Converted`] will be returned
|
||||||
|
|||||||
@@ -131,6 +131,26 @@ impl Beatmap {
|
|||||||
Converted::unchecked_from_ref(self)
|
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.
|
/// Attempt to convert a [`Beatmap`] to the specified mode.
|
||||||
///
|
///
|
||||||
/// If the conversion is incompatible the [`Beatmap`] will be returned
|
/// If the conversion is incompatible the [`Beatmap`] will be returned
|
||||||
|
|||||||
Reference in New Issue
Block a user