return Result<_, Self> instead of Option

This commit is contained in:
MaxOhn
2024-03-08 11:49:57 +01:00
parent d711840a11
commit e3dcec8584
2 changed files with 15 additions and 17 deletions
+8 -12
View File
@@ -95,7 +95,7 @@ impl<'map> OsuPerformance<'map> {
/// Attempt to convert the map to the specified mode.
///
/// Returns `None` if the internal beatmap was already replaced with
/// Returns `Err(self)` if the internal beatmap was already replaced with
/// [`OsuDifficultyAttributes`], i.e. if
/// [`OsuPerformance::from_attributes`] or
/// [`OsuPerformance::generate_state`] was called.
@@ -104,18 +104,14 @@ impl<'map> OsuPerformance<'map> {
/// replaced, use [`mode_or_ignore`] instead.
///
/// [`mode_or_ignore`]: Self::mode_or_ignore
pub fn try_mode(self, mode: GameMode) -> Option<Performance<'map>> {
// The `Ok`-variant is larger in size
#[allow(clippy::result_large_err)]
pub fn try_mode(self, mode: GameMode) -> Result<Performance<'map>, Self> {
match mode {
GameMode::Osu => Some(Performance::Osu(self)),
GameMode::Taiko => TaikoPerformance::try_from(self)
.map(Performance::Taiko)
.ok(),
GameMode::Catch => CatchPerformance::try_from(self)
.map(Performance::Catch)
.ok(),
GameMode::Mania => ManiaPerformance::try_from(self)
.map(Performance::Mania)
.ok(),
GameMode::Osu => Ok(Performance::Osu(self)),
GameMode::Taiko => TaikoPerformance::try_from(self).map(Performance::Taiko),
GameMode::Catch => CatchPerformance::try_from(self).map(Performance::Catch),
GameMode::Mania => ManiaPerformance::try_from(self).map(Performance::Mania),
}
}