Move join_display_values to utils

master
Simon Bruder 2020-06-26 21:10:51 +02:00
parent 6e77c957cc
commit 60b74c7e97
No known key found for this signature in database
GPG Key ID: 6F03E0000CC5B62F
2 changed files with 18 additions and 14 deletions

View File

@ -2,6 +2,8 @@ use num_derive::ToPrimitive;
use num_traits::ToPrimitive;
use std::fmt;
use crate::utils;
// Generic Type Aliases
pub type OsuPixel = i16;
pub type DecimalOsuPixel = f32;
@ -19,14 +21,6 @@ fn bitflags(flags: [bool; 8]) -> u8 {
value
}
fn join_display_values<T: fmt::Display>(iterable: Vec<T>, separator: &'_ str) -> String {
iterable
.iter()
.map(|val| val.to_string())
.collect::<Vec<_>>()
.join(&separator)
}
fn assemble_hit_object_type(hit_object_type: u8, new_combo: bool, skip_combo_colours: U3) -> u8 {
let hit_object_type = 1u8 << hit_object_type;
let new_combo = if new_combo { 0b0000_0010_u8 } else { 0u8 };
@ -182,7 +176,7 @@ impl fmt::Display for Events {
[Events]\n\
{}\n\
",
join_display_values(self.0.clone(), "\n")
utils::join_display_values(self.0.clone(), "\n")
)
}
}
@ -243,7 +237,7 @@ impl fmt::Display for TimingPoints {
[TimingPoints]\n\
{}\n\
",
join_display_values(self.0.clone(), "\n")
utils::join_display_values(self.0.clone(), "\n")
)
}
}
@ -313,7 +307,7 @@ impl fmt::Display for Colours {
[Colours]\n\
{}\n\
",
join_display_values(self.0.clone(), "\n")
utils::join_display_values(self.0.clone(), "\n")
)
}
}
@ -346,7 +340,7 @@ impl fmt::Display for Colour {
f,
"{} : {}",
self.scope,
join_display_values(self.colour.to_vec(), ",")
utils::join_display_values(self.colour.to_vec(), ",")
)
}
}
@ -497,7 +491,7 @@ impl fmt::Display for HitObject {
.join("|"),
slides,
length,
join_display_values(edge_sounds.clone(), "|"),
utils::join_display_values(edge_sounds.clone(), "|"),
edge_sets
.iter()
.map(|set| format!(
@ -559,7 +553,7 @@ impl fmt::Display for HitObjects {
[HitObjects]\n\
{}\n\
",
join_display_values(self.0.clone(), "\n")
utils::join_display_values(self.0.clone(), "\n")
)
}
}

View File

@ -1,3 +1,5 @@
use std::fmt;
pub fn get_nth_bit(byte: u8, n: u8) -> bool {
((byte & (0b1 << n)) >> n) != 0
}
@ -9,3 +11,11 @@ pub fn byte_to_bitarray(byte: u8) -> [bool; 8] {
}
bitarray
}
pub fn join_display_values<T: fmt::Display>(iterable: Vec<T>, separator: &'_ str) -> String {
iterable
.iter()
.map(|val| val.to_string())
.collect::<Vec<_>>()
.join(&separator)
}