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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
use PhantomData;
/// This trait makes a struct available for use as component properties.
///
/// # Examples
///
/// ```
/// # use iocraft::prelude::*;
/// #[derive(Default, Props)]
/// struct MyProps {
/// foo: String,
/// }
/// ```
///
/// Unowned data is okay too:
///
/// ```
/// # use iocraft::prelude::*;
/// #[derive(Default, Props)]
/// struct MyProps<'a> {
/// foo: &'a str,
/// }
/// ```
///
/// However, a field that would make the struct
/// [invariant](https://doc.rust-lang.org/nomicon/subtyping.html) is not okay and will not compile:
///
/// ```compile_fail
/// # use iocraft::prelude::*;
/// # struct MyType<'a>(&'a str);
/// #[derive(Default, Props)]
/// struct MyProps<'a> {
/// foo: &'a mut MyType<'a>,
/// }
/// ```
///
/// Properties can be used by custom components like so:
///
/// ```
/// # use iocraft::prelude::*;
/// #[derive(Default, Props)]
/// struct GreetingProps<'a> {
/// name: &'a str,
/// }
///
/// #[component]
/// fn Greeting<'a>(props: &GreetingProps<'a>) -> impl Into<AnyElement<'a>> {
/// element! {
/// Text(content: format!("Hello, {}!", props.name))
/// }
/// }
/// ```
///
/// If you are building a component for use in a library, you will typically also want to mark your
/// props as `#[non_exhaustive]` so that you can add new fields in the future without creating
/// breaking changes.
///
/// # Reserved Names
///
/// An implicitly added "key" prop is used to maintain state across renders and should not be used
/// as a field name (see the [`element!`](crate::element!) macro for details). The
/// [`#[derive(Props)]`](derive@crate::Props) macro will give you an error at compile time if you
/// attempt to use it:
///
/// ```compile_fail
/// # use iocraft::prelude::*;
/// #[derive(Default, Props)]
/// struct MyProps {
/// key: i32,
/// }
/// ```
///
/// # Safety
///
/// This requires the type to be [covariant](https://doc.rust-lang.org/nomicon/subtyping.html). If
/// implemented for a type that is not actually covariant, then the safety of the program is
/// compromised. You can use the [`#[derive(Props)]`](derive@crate::Props) macro to implement this trait safely. If the
/// type is not actually covariant, the derive macro will give you an error at compile-time.
pub unsafe
;
// SAFETY: Safe because `Props` must be `Send` and `Sync`.
unsafe
// SAFETY: Safe because `Props` must be `Sync`.
unsafe