Merge remote-tracking branch 'upstream/main'
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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pub use inner::*;
|
||||
|
||||
#[cfg(feature = "compact_strains")]
|
||||
#[cfg(not(feature = "raw_strains"))]
|
||||
mod inner {
|
||||
use std::{iter::Copied, slice::Iter};
|
||||
|
||||
@@ -318,14 +318,14 @@ mod inner {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "compact_strains"))]
|
||||
#[cfg(feature = "raw_strains")]
|
||||
mod inner {
|
||||
use std::{
|
||||
iter::Copied,
|
||||
slice::{Iter, IterMut},
|
||||
};
|
||||
|
||||
/// Plain wrapper around `Vec<f64>` because the `compact_strains` feature
|
||||
/// Plain wrapper around `Vec<f64>` because the `raw_strains` feature
|
||||
/// is disabled.
|
||||
#[derive(Clone)]
|
||||
pub struct StrainsVec {
|
||||
|
||||
+4
-4
@@ -139,9 +139,9 @@ impl<T: fmt::Debug> fmt::Debug for Weak<T> {
|
||||
/// ```compile_fail
|
||||
/// use akatsuki_pp::{taiko::TaikoGradualDifficulty, Beatmap, Difficulty};
|
||||
///
|
||||
/// let converted = Beatmap::from_bytes(&[]).unwrap().unchecked_into_converted();
|
||||
/// let map = Beatmap::from_bytes(&[]).unwrap();
|
||||
/// let difficulty = Difficulty::new();
|
||||
/// let mut gradual = TaikoGradualDifficulty::new(&difficulty, &converted);
|
||||
/// let mut gradual = TaikoGradualDifficulty::new(&difficulty, &map).unwrap();
|
||||
///
|
||||
/// // Rc<RefCell<_>> cannot be shared across threads so compilation should fail
|
||||
/// std::thread::spawn(move || { let _ = gradual.next(); });
|
||||
@@ -155,8 +155,8 @@ mod tests {
|
||||
fn share_gradual_taiko() {
|
||||
use crate::{taiko::TaikoGradualDifficulty, Beatmap, Difficulty};
|
||||
|
||||
let converted = Beatmap::from_bytes(&[]).unwrap().unchecked_into_converted();
|
||||
let mut gradual = TaikoGradualDifficulty::new(Difficulty::new(), &converted);
|
||||
let map = Beatmap::from_bytes(&[]).unwrap();
|
||||
let mut gradual = TaikoGradualDifficulty::new(Difficulty::new(), &map).unwrap();
|
||||
|
||||
// Arc<RwLock<_>> *can* be shared across threads so this should compile
|
||||
std::thread::spawn(move || {
|
||||
|
||||
Reference in New Issue
Block a user