Skip to content

Commit

Permalink
simplify From impls
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn committed Apr 1, 2024
1 parent 3294fb2 commit 37d3951
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 102 deletions.
8 changes: 4 additions & 4 deletions src/any/performance/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ macro_rules! impl_from_mode {

impl<'map> IntoModePerformance<'map, mode!()> for Converted<'map, mode!()> {
fn into_performance(self) -> <mode!() as IGameMode>::Performance<'map> {
self.into()
<mode!() as IGameMode>::Performance::from_map_or_attrs(self.into())
}
}

impl<'map> IntoModePerformance<'map, mode!()> for &'map Converted<'_, mode!()> {
fn into_performance(self) -> <mode!() as IGameMode>::Performance<'map> {
self.as_owned().into()
<mode!() as IGameMode>::Performance::from_map_or_attrs(self.as_owned().into())
}
}

impl<'map> IntoModePerformance<'map, mode!()> for crate::$module::$diff {
fn into_performance(self) -> <mode!() as IGameMode>::Performance<'map> {
self.performance()
<mode!() as IGameMode>::Performance::from_map_or_attrs(self.into())
}
}

impl<'map> IntoModePerformance<'map, mode!()> for crate::$module::$perf {
fn into_performance(self) -> <mode!() as IGameMode>::Performance<'map> {
self.performance()
<mode!() as IGameMode>::Performance::from_map_or_attrs(self.difficulty.into())
}
}

Expand Down
27 changes: 4 additions & 23 deletions src/catch/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{

use super::{
attributes::{CatchDifficultyAttributes, CatchPerformanceAttributes},
convert::CatchBeatmap,
score_state::CatchScoreState,
Catch,
};
Expand Down Expand Up @@ -418,7 +417,7 @@ impl<'map> CatchPerformance<'map> {
inner.calculate()
}

const fn from_map_or_attrs(map_or_attrs: MapOrAttrs<'map, Catch>) -> Self {
pub(crate) const fn from_map_or_attrs(map_or_attrs: MapOrAttrs<'map, Catch>) -> Self {
Self {
map_or_attrs,
difficulty: Difficulty::new(),
Expand Down Expand Up @@ -481,27 +480,9 @@ impl<'map> TryFrom<OsuPerformance<'map>> for CatchPerformance<'map> {
}
}

impl<'map> From<CatchBeatmap<'map>> for CatchPerformance<'map> {
fn from(map: CatchBeatmap<'map>) -> Self {
Self::from_map_or_attrs(map.into())
}
}

impl<'map> From<&'map CatchBeatmap<'_>> for CatchPerformance<'map> {
fn from(map: &'map CatchBeatmap<'_>) -> Self {
Self::from_map_or_attrs(map.as_owned().into())
}
}

impl From<CatchDifficultyAttributes> for CatchPerformance<'_> {
fn from(attrs: CatchDifficultyAttributes) -> Self {
Self::from_map_or_attrs(attrs.into())
}
}

impl From<CatchPerformanceAttributes> for CatchPerformance<'_> {
fn from(attrs: CatchPerformanceAttributes) -> Self {
Self::from_map_or_attrs(attrs.difficulty.into())
impl<'map, T: IntoModePerformance<'map, Catch>> From<T> for CatchPerformance<'map> {
fn from(into: T) -> Self {
into.into_performance()
}
}

Expand Down
27 changes: 4 additions & 23 deletions src/mania/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{

use super::{
attributes::{ManiaDifficultyAttributes, ManiaPerformanceAttributes},
convert::ManiaBeatmap,
score_state::ManiaScoreState,
Mania,
};
Expand Down Expand Up @@ -770,7 +769,7 @@ impl<'map> ManiaPerformance<'map> {
inner.calculate()
}

const fn from_map_or_attrs(map_or_attrs: MapOrAttrs<'map, Mania>) -> Self {
pub(crate) const fn from_map_or_attrs(map_or_attrs: MapOrAttrs<'map, Mania>) -> Self {
Self {
map_or_attrs,
difficulty: Difficulty::new(),
Expand Down Expand Up @@ -835,27 +834,9 @@ impl<'map> TryFrom<OsuPerformance<'map>> for ManiaPerformance<'map> {
}
}

impl<'map> From<ManiaBeatmap<'map>> for ManiaPerformance<'map> {
fn from(map: ManiaBeatmap<'map>) -> Self {
Self::from_map_or_attrs(map.into())
}
}

impl<'map> From<&'map ManiaBeatmap<'_>> for ManiaPerformance<'map> {
fn from(map: &'map ManiaBeatmap<'_>) -> Self {
Self::from_map_or_attrs(map.as_owned().into())
}
}

impl From<ManiaDifficultyAttributes> for ManiaPerformance<'_> {
fn from(attrs: ManiaDifficultyAttributes) -> Self {
Self::from_map_or_attrs(attrs.into())
}
}

impl From<ManiaPerformanceAttributes> for ManiaPerformance<'_> {
fn from(attrs: ManiaPerformanceAttributes) -> Self {
Self::from_map_or_attrs(attrs.difficulty.into())
impl<'map, T: IntoModePerformance<'map, Mania>> From<T> for ManiaPerformance<'map> {
fn from(into: T) -> Self {
into.into_performance()
}
}

Expand Down
27 changes: 4 additions & 23 deletions src/osu/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{

use super::{
attributes::{OsuDifficultyAttributes, OsuPerformanceAttributes},
convert::OsuBeatmap,
score_state::OsuScoreState,
Osu,
};
Expand Down Expand Up @@ -500,7 +499,7 @@ impl<'map> OsuPerformance<'map> {
inner.calculate()
}

const fn from_map_or_attrs(map_or_attrs: MapOrAttrs<'map, Osu>) -> Self {
pub(crate) const fn from_map_or_attrs(map_or_attrs: MapOrAttrs<'map, Osu>) -> Self {
Self {
map_or_attrs,
difficulty: Difficulty::new(),
Expand All @@ -515,27 +514,9 @@ impl<'map> OsuPerformance<'map> {
}
}

impl<'map> From<OsuBeatmap<'map>> for OsuPerformance<'map> {
fn from(map: OsuBeatmap<'map>) -> Self {
Self::from_map_or_attrs(map.into())
}
}

impl<'map> From<&'map OsuBeatmap<'_>> for OsuPerformance<'map> {
fn from(map: &'map OsuBeatmap<'_>) -> Self {
Self::from_map_or_attrs(map.as_owned().into())
}
}

impl From<OsuDifficultyAttributes> for OsuPerformance<'_> {
fn from(attrs: OsuDifficultyAttributes) -> Self {
Self::from_map_or_attrs(attrs.into())
}
}

impl From<OsuPerformanceAttributes> for OsuPerformance<'_> {
fn from(attrs: OsuPerformanceAttributes) -> Self {
Self::from_map_or_attrs(attrs.difficulty.into())
impl<'map, T: IntoModePerformance<'map, Osu>> From<T> for OsuPerformance<'map> {
fn from(into: T) -> Self {
into.into_performance()
}
}

Expand Down
27 changes: 4 additions & 23 deletions src/taiko/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{

use super::{
attributes::{TaikoDifficultyAttributes, TaikoPerformanceAttributes},
convert::TaikoBeatmap,
score_state::TaikoScoreState,
Taiko,
};
Expand Down Expand Up @@ -311,7 +310,7 @@ impl<'map> TaikoPerformance<'map> {
inner.calculate()
}

const fn from_map_or_attrs(map_or_attrs: MapOrAttrs<'map, Taiko>) -> Self {
pub(crate) const fn from_map_or_attrs(map_or_attrs: MapOrAttrs<'map, Taiko>) -> Self {
Self {
map_or_attrs,
difficulty: Difficulty::new(),
Expand Down Expand Up @@ -372,27 +371,9 @@ impl<'map> TryFrom<OsuPerformance<'map>> for TaikoPerformance<'map> {
}
}

impl<'map> From<TaikoBeatmap<'map>> for TaikoPerformance<'map> {
fn from(map: TaikoBeatmap<'map>) -> Self {
Self::from_map_or_attrs(map.into())
}
}

impl<'map> From<&'map TaikoBeatmap<'_>> for TaikoPerformance<'map> {
fn from(map: &'map TaikoBeatmap<'_>) -> Self {
Self::from_map_or_attrs(map.as_owned().into())
}
}

impl From<TaikoDifficultyAttributes> for TaikoPerformance<'_> {
fn from(attrs: TaikoDifficultyAttributes) -> Self {
Self::from_map_or_attrs(attrs.into())
}
}

impl From<TaikoPerformanceAttributes> for TaikoPerformance<'_> {
fn from(attrs: TaikoPerformanceAttributes) -> Self {
Self::from_map_or_attrs(attrs.difficulty.into())
impl<'map, T: IntoModePerformance<'map, Taiko>> From<T> for TaikoPerformance<'map> {
fn from(into: T) -> Self {
into.into_performance()
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/util/map_or_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ impl<'map, M: IGameMode> From<Converted<'map, M>> for MapOrAttrs<'map, M> {
}
}

impl<'map, M: IGameMode> From<&'map Converted<'_, M>> for MapOrAttrs<'map, M> {
fn from(converted: &'map Converted<'_, M>) -> Self {
Self::Map(converted.as_owned())
}
}

macro_rules! from_attrs {
(
$(
Expand Down

0 comments on commit 37d3951

Please sign in to comment.