feat!: overhaul convert api
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
use std::{
|
||||
any,
|
||||
fmt::{Debug, Formatter, Result as FmtResult},
|
||||
marker::PhantomData,
|
||||
};
|
||||
|
||||
pub struct GenericFormatter<T>(PhantomData<T>);
|
||||
|
||||
impl<T> GenericFormatter<T> {
|
||||
pub const fn new() -> Self {
|
||||
Self(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Debug for GenericFormatter<T> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
fn fmt_stripped(full_type_name: &str, f: &mut Formatter<'_>) -> FmtResult {
|
||||
// Strip fully qualified syntax
|
||||
if let Some(position) = full_type_name.rfind("::") {
|
||||
if let Some(type_name) = full_type_name.get(position + 2..) {
|
||||
f.write_str(type_name)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fmt_stripped(any::type_name::<T>(), f)
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
use std::fmt::{Debug, Formatter, Result as FmtResult};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
fmt::{Debug, Formatter, Result as FmtResult},
|
||||
};
|
||||
|
||||
use crate::model::{beatmap::Converted, mode::IGameMode};
|
||||
use crate::{model::mode::IGameMode, Beatmap};
|
||||
|
||||
pub enum MapOrAttrs<'map, M: IGameMode> {
|
||||
Map(Converted<'map, M>),
|
||||
Map(Cow<'map, Beatmap>),
|
||||
Attrs(M::DifficultyAttributes),
|
||||
}
|
||||
|
||||
@@ -69,9 +72,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'map, M: IGameMode> From<Converted<'map, M>> for MapOrAttrs<'map, M> {
|
||||
fn from(converted: Converted<'map, M>) -> Self {
|
||||
Self::Map(converted)
|
||||
impl<'map, M: IGameMode> From<&'map Beatmap> for MapOrAttrs<'map, M> {
|
||||
fn from(map: &'map Beatmap) -> Self {
|
||||
Self::Map(Cow::Borrowed(map))
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: IGameMode> From<Beatmap> for MapOrAttrs<'_, M> {
|
||||
fn from(map: Beatmap) -> Self {
|
||||
Self::Map(Cow::Owned(map))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
pub mod float_ext;
|
||||
pub mod generic_fmt;
|
||||
pub mod limited_queue;
|
||||
pub mod map_or_attrs;
|
||||
pub mod random;
|
||||
|
||||
Reference in New Issue
Block a user