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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use Deref;
/// A static string held by reference so a view can record it in place.
///
/// This is the most efficient way to pass a `&'static str` to a `view!`.
/// Use it to optimize your rendering, for example for static class strings.
///
/// ```rust
/// # use topcoat::view::{PromotedStr, View, component, view};
/// # #[component]
/// # async fn example() -> topcoat::Result<impl View> {
/// Ok(view! {
/// <div>(PromotedStr(&"hello"))</div>
/// })
/// # }
/// ```
///
/// The leading `&` is what makes this work: Rust promotes a reference to a
/// constant into the binary's read-only data. Only a constant can be
/// promoted, so a string that is only known at run time goes through
/// [`StaticStr`] instead.
;
/// A static string a view records without copying it.
///
/// The `&str` implementations copy their contents into the view, since the
/// view can outlive the borrow. A `&'static str` outlives every view, so
/// wrapping one in this type records the string as is:
///
/// ```rust
/// # use topcoat::view::{StaticStr, View, component, view};
/// # #[component]
/// # async fn example() -> topcoat::Result<impl View> {
/// # let name: &'static str = "hello";
/// Ok(view! {
/// <div>(StaticStr(name))</div>
/// })
/// # }
/// ```
///
/// A string written as a literal can be further optimized by using [`PromotedStr`].
;
/// A wrapper that marks its contents as already-safe HTML.
///
/// Use this only for trusted markup such as pre-rendered or sanitized HTML.
/// Passing untrusted input through this type defeats the runtime's escaping.
T);