1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use fmt;
/// Open serialization trait for CSS-like values.
///
/// This powers both [`fmt::Display`]-style formatting and the zero-allocation
/// [`write_to`](CssWriteTo::write_to) method through a single implementation. Downstream types
/// may implement this trait for application-specific serialization, but doing so does not make a
/// type eligible for checked declarations; that capability is represented by the sealed
/// [`CheckedCssValue`](crate::CheckedCssValue) trait.
///
/// ```rust
/// use std::fmt;
/// use leptos_css::CssWriteTo;
///
/// struct ExternalValue(&'static str);
///
/// impl CssWriteTo for ExternalValue {
/// fn css_fmt<W: fmt::Write>(&self, output: &mut W) -> fmt::Result {
/// output.write_str(self.0)
/// }
/// }
///
/// let mut output = String::new();
/// ExternalValue("application-specific").write_to(&mut output);
/// assert_eq!(output, "application-specific");
/// ```
///
/// Serialization alone cannot enter the checked custom-property API:
///
/// ```compile_fail
/// use std::fmt;
/// use leptos_css::{CssCustomProperty, CssWriteTo};
///
/// struct Raw(&'static str);
///
/// impl CssWriteTo for Raw {
/// fn css_fmt<W: fmt::Write>(&self, output: &mut W) -> fmt::Result {
/// output.write_str(self.0)
/// }
/// }
///
/// let property = CssCustomProperty::<Raw>::new("--unsafe");
/// let _ = property.declare(Raw("red;color:lime"));
/// ```