osu_file_parser/helper/
mod.rs1pub mod macros;
2pub mod trait_ext;
3
4use std::num::ParseIntError;
5
6use thiserror::Error;
7
8use crate::osu_file::{Version, VersionedToString};
9
10pub fn pipe_vec_to_string<T>(vec: &[T], version: Version) -> String
11where
12 T: VersionedToString,
13{
14 vec.iter()
15 .map(|s| s.to_string(version).unwrap())
16 .collect::<Vec<_>>()
17 .join("|")
18}
19
20pub fn nth_bit_state_i64(value: i64, nth_bit: u8) -> bool {
21 value >> nth_bit & 1 == 1
22}
23
24pub fn parse_zero_one_bool(value: &str) -> Result<bool, ParseZeroOneBoolError> {
25 let value = value.parse()?;
26
27 match value {
28 0 => Ok(false),
29 1 => Ok(true),
30 _ => Err(ParseZeroOneBoolError::InvalidValue),
31 }
32}
33
34#[derive(Debug, Error)]
35pub enum ParseZeroOneBoolError {
36 #[error(transparent)]
37 ParseIntError(#[from] ParseIntError),
38 #[error("Error parsing value as `true` or `false`, expected value of 0 or 1")]
39 InvalidValue,
40}