use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
pub type BgColor<S = DefaultStr> = S;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Mode<S: BosStr = DefaultStr> {
Edit,
View,
Other(S),
}
impl<S: BosStr> Mode<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Edit => "edit",
Self::View => "view",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"edit" => Self::Edit,
"view" => Self::View,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> AsRef<str> for Mode<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> core::fmt::Display for Mode<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> serde::Serialize for Mode<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: serde::Deserialize<'de> + BosStr> serde::Deserialize<'de> for Mode<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr> jacquard_common::IntoStatic for Mode<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = Mode<S::Output>;
fn into_static(self) -> Self::Output {
match self {
Mode::Edit => Mode::Edit,
Mode::View => Mode::View,
Mode::Other(v) => Mode::Other(v.into_static()),
}
}
}
pub type PrimaryColor<S = DefaultStr> = S;