use crate::utils::normalize_class_list_string;
pub trait ClassToggle {
fn to_class_toggle(&self) -> bool;
}
impl<T, F> ClassToggle for F
where
F: Fn() -> T,
T: ClassToggle,
{
fn to_class_toggle(&self) -> bool {
self().to_class_toggle()
}
}
impl<T, E> ClassToggle for Result<T, E>
where
T: ClassToggle,
{
fn to_class_toggle(&self) -> bool {
if let Ok(value) = self {
value.to_class_toggle()
} else {
false
}
}
}
impl<T> ClassToggle for Option<T>
where
T: ClassToggle,
{
fn to_class_toggle(&self) -> bool {
if let Some(value) = self {
value.to_class_toggle()
} else {
false
}
}
}
impl ClassToggle for bool {
fn to_class_toggle(&self) -> bool {
*self
}
}
pub trait ClassList {
fn to_class_list(&self, normalize: bool) -> String;
}
impl<T, F> ClassList for F
where
F: Fn() -> T,
T: ClassList,
{
fn to_class_list(&self, normalize: bool) -> String {
self().to_class_list(normalize)
}
}
impl<T, E> ClassList for Result<T, E>
where
T: ClassList,
{
fn to_class_list(&self, normalize: bool) -> String {
if let Ok(value) = self {
value.to_class_list(normalize)
} else {
String::default()
}
}
}
impl<T> ClassList for Option<T>
where
T: ClassList,
{
fn to_class_list(&self, normalize: bool) -> String {
if let Some(value) = self {
value.to_class_list(normalize)
} else {
String::default()
}
}
}
impl ClassList for String {
fn to_class_list(&self, normalize: bool) -> String {
if normalize {
normalize_class_list_string(self.clone())
} else {
self.clone()
}
}
}
impl ClassList for &str {
fn to_class_list(&self, normalize: bool) -> String {
if normalize {
normalize_class_list_string(self.to_string())
} else {
self.to_string()
}
}
}
impl ClassList for str {
fn to_class_list(&self, normalize: bool) -> String {
if normalize {
normalize_class_list_string(self.to_string())
} else {
self.to_string()
}
}
}