use alloc::string::String;
use alloc::sync::Arc;
use crate::value::{SafeKind, ToValue, Value};
macro_rules! safe_content {
($($(#[$m:meta])* $name:ident => $kind:ident),+ $(,)?) => {$(
$(#[$m])*
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct $name(pub Arc<str>);
impl From<&str> for $name {
fn from(s: &str) -> Self { $name(Arc::from(s)) }
}
impl From<String> for $name {
fn from(s: String) -> Self { $name(Arc::from(s)) }
}
impl From<Arc<str>> for $name {
fn from(s: Arc<str>) -> Self { $name(s) }
}
impl ToValue for $name {
fn to_value(&self) -> Value {
Value::Safe { kind: SafeKind::$kind, s: Arc::clone(&self.0) }
}
}
impl From<$name> for Value {
fn from(v: $name) -> Value {
Value::Safe { kind: SafeKind::$kind, s: v.0 }
}
}
)+};
}
safe_content! {
HTML => Html,
HTMLAttr => HtmlAttr,
JS => Js,
JSStr => JsStr,
CSS => Css,
URL => Url,
Srcset => Srcset,
}