topcoat_view/props.rs
1/// A properties struct whose builder checks required fields at compile time.
2///
3/// Implemented by [`#[derive(Props)]`][derive]. The derive also generates an
4/// inherent `builder()` function on the struct, so this trait only needs to be
5/// in scope when the builder is constructed generically.
6///
7/// [derive]: derive.Props.html
8pub trait Props {
9 /// The builder type in its initial state, with no properties set.
10 type Builder;
11
12 /// Returns a builder with no properties set.
13 fn builder() -> Self::Builder;
14}
15
16/// Marks a required property as set in a generated builder.
17///
18/// Calling a required property's setter changes its type parameter to
19/// [`Set`]. See [`#[derive(Props)]`][derive].
20///
21/// [derive]: derive.Props.html
22pub struct Set;
23
24/// Indicates that a generated builder's property has been set.
25///
26/// A builder's `build()` method requires this trait for every required
27/// property. Unset properties produce a compile error naming the missing field.
28#[diagnostic::on_unimplemented(
29 message = "missing required property `{Self}`",
30 label = "the property `{Self}` was not set",
31 note = "every property without `#[default]` must be set before calling `build()`"
32)]
33pub trait IsSet {}
34
35impl IsSet for Set {}