use colored::{ColoredString, Colorize};
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct System {
pub label: String,
pub display_name: String,
pub rgb: [u8; 3],
pub directory: String,
pub games_are_directories: bool,
}
impl System {
#[must_use]
pub fn new(
label: &str,
display_name: &str,
rgb: [u8; 3],
dir_name: &str,
games_are_directories: bool,
) -> Self {
Self {
label: String::from(label),
display_name: String::from(display_name),
directory: String::from(dir_name),
rgb,
games_are_directories,
}
}
#[must_use]
pub fn colored_string(&self) -> ColoredString {
let rgb = &self.rgb;
self.display_name.truecolor(rgb[0], rgb[1], rgb[2])
}
}
impl std::fmt::Display for System {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.colored_string())
}
}
impl std::hash::Hash for System {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.directory.hash(state);
self.games_are_directories.hash(state);
}
}