leptos_css/checked_value.rs
1use crate::serialization::CssWriteTo;
2
3pub(crate) mod sealed {
4 pub trait Sealed {}
5}
6
7/// A crate-validated CSS value grammar eligible for checked declarations.
8///
9/// This trait is sealed. Downstream types may implement [`CssWriteTo`] for serialization, but
10/// only crate-owned closed grammars implement this trait.
11///
12/// ```compile_fail
13/// use std::fmt;
14/// use leptos_css::{CheckedCssValue, CssWriteTo};
15///
16/// struct ExternalValue;
17///
18/// impl CssWriteTo for ExternalValue {
19/// fn css_fmt<W: fmt::Write>(&self, _output: &mut W) -> fmt::Result {
20/// Ok(())
21/// }
22/// }
23///
24/// impl CheckedCssValue for ExternalValue {}
25/// ```
26pub trait CheckedCssValue: CssWriteTo + sealed::Sealed {}
27
28impl<T> CheckedCssValue for T where T: CssWriteTo + sealed::Sealed {}
29
30macro_rules! impl_checked_value {
31 ($($ty:ty),+ $(,)?) => {$ (
32 impl fmt::Display for $ty {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 self.css_fmt(f)
35 }
36 }
37
38 impl $crate::checked_value::sealed::Sealed for $ty {}
39 )+};
40}
41
42pub(crate) use impl_checked_value;