use std::path::PathBuf;
pub fn print_type<T: ?Sized>(_: &T) {
println!("{}", core::any::type_name::<T>())
}
pub(crate) fn fix_path_separators(path: &str) -> PathBuf {
#[cfg(target_os = "windows")]
{ PathBuf::from(str::replace(path, r"/", r"\")) }
#[cfg(not(target_os = "windows"))]
{ PathBuf::from(str::replace(path, r"\", r"/")) }
}
pub(crate) fn check_f32(value: &str) -> f32 {
let num: f32 = value.parse::<f32>()
.expect(&format!("ERROR: `{}` is not a valid f32 number", value));
num
}
pub(crate) fn check_f32_between(value: &str, min: f32, max: f32) -> Option<f32> {
let num = check_f32(value);
match num {
num if (min..=max).contains(&num) => Some(num),
_ => None
}
}
pub(crate) fn check_u8(value: &str) -> u8 {
let num: u8 = value.parse::<u8>()
.expect(&format!("ERROR: `{}` is not a valid i8 number", value));
num
}
pub(crate) fn check_u8_between(value: &str, min: u8, max: u8) -> Option<u8> {
let num = check_u8(value);
if num >= min && num <= max { return Some(num); }
else { None }
}
pub(crate) fn check_i8(value: &str) -> i8 {
let num: i8 = value.parse::<i8>()
.expect(&format!("ERROR: `{}` is not a valid i8 number", value));
num
}
pub(crate) fn check_i8_between(value: &str, min: i8, max: i8) -> Option<i8> {
let num = check_i8(value);
if num >= min && num <= max { return Some(num); }
else { None }
}
pub(crate) fn check_i16(value: &str) -> i16 {
let num: i16 = value.parse::<i16>()
.expect(&format!("ERROR: `{}` is not a valid i16 number", value));
num
}
pub(crate) fn check_i16_between(value: &str, min: i16, max: i16) -> Option<i16> {
let num = check_i16(value);
if num >= min && num <= max { return Some(num); }
else { None }
}
pub(crate) fn check_u16(value: &str) -> u16 {
let num: u16 = value.parse::<u16>()
.expect(&format!("ERROR: `{}` is not a valid u16 number", value));
num
}
pub(crate) fn check_u16_between(value: &str, min: u16, max: u16) -> Option<u16> {
let num = check_u16(value);
if num >= min && num <= max { return Some(num); }
else { None }
}
pub(crate) fn check_u32(value: &str) -> u32 {
let num: u32 = value.parse::<u32>()
.expect(&format!("ERROR: `{}` is not a valid u32 number", value));
num
}
pub(crate) fn check_u32_between(value: &str, min: u32, max: u32) -> Option<u32> {
let num = check_u32(value);
if num >= min && num <= max { return Some(num); }
else { None }
}