restructure Difficulty and ModeDifficulty

This commit is contained in:
MaxOhn
2024-03-03 09:57:44 +01:00
parent 3705338d12
commit e749a791fc
39 changed files with 446 additions and 448 deletions
+30
View File
@@ -0,0 +1,30 @@
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
View File
@@ -1,4 +1,5 @@
pub mod float_ext;
pub mod generic_fmt;
pub mod limited_queue;
pub mod map_or_attrs;
pub mod mods;
+4 -4
View File
@@ -133,10 +133,10 @@ impl<T: fmt::Debug> fmt::Debug for Weak<T> {
}
/// ```compile_fail
/// use rosu_pp::{taiko::TaikoGradualDifficulty, Beatmap, ModeDifficulty};
/// use rosu_pp::{taiko::TaikoGradualDifficulty, Beatmap, Difficulty};
///
/// let converted = Beatmap::from_bytes(&[]).unwrap().unchecked_into_converted();
/// let difficulty = ModeDifficulty::new();
/// let difficulty = Difficulty::new();
/// let mut gradual = TaikoGradualDifficulty::new(&difficulty, &converted);
///
/// // Rc<RefCell<_>> cannot be shared across threads so compilation should fail
@@ -149,10 +149,10 @@ const fn _share_gradual_taiko() {}
mod tests {
#[test]
fn share_gradual_taiko() {
use crate::{taiko::TaikoGradualDifficulty, Beatmap, ModeDifficulty};
use crate::{taiko::TaikoGradualDifficulty, Beatmap, Difficulty};
let converted = Beatmap::from_bytes(&[]).unwrap().unchecked_into_converted();
let difficulty = ModeDifficulty::new();
let difficulty = Difficulty::new();
let mut gradual = TaikoGradualDifficulty::new(&difficulty, &converted);
// Arc<RwLock<_>> *can* be shared across threads so this should compile