Skip to content

Commit 43d654c

Browse files
committed
Fix up example
1 parent 845b16e commit 43d654c

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

examples/reflection/reflection_types.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,43 @@ pub struct A {
2424
z: HashMap<String, f32>,
2525
}
2626

27-
/// Deriving reflect on a unit struct will implement `Reflect` and `Struct` traits
27+
/// Deriving reflect on a unit struct will implement the `Reflect` and `Struct` traits
2828
#[derive(Reflect)]
2929
pub struct B;
3030

31-
/// Deriving reflect on a tuple struct will implement `Reflect` and `TupleStruct` traits
31+
/// Deriving reflect on a tuple struct will implement the `Reflect` and `TupleStruct` traits
3232
#[derive(Reflect)]
3333
pub struct C(usize);
3434

35+
/// Deriving reflect on an enum will implement the `Reflect` and `Enum` traits
36+
#[derive(Reflect)]
37+
pub enum D {
38+
A,
39+
B(usize),
40+
C {
41+
foo: f32,
42+
bar: bool
43+
}
44+
}
45+
3546
/// Reflect has "built in" support for some common traits like `PartialEq`, `Hash`, and `Serialize`.
36-
/// These are exposed via methods like `Reflect::hash()`, `Reflect::partial_eq()`, and
37-
/// `Reflect::serialize()`. You can force these implementations to use the actual trait
47+
/// These are exposed via methods like `Reflect::reflect_hash()`, `Reflect::reflect_partial_eq()`, and
48+
/// `Reflect::serializable()`. You can force these implementations to use the actual trait
3849
/// implementations (instead of their defaults) like this:
3950
#[derive(Reflect, Hash, Serialize, PartialEq)]
4051
#[reflect(Hash, Serialize, PartialEq)]
41-
pub struct D {
52+
pub struct E {
4253
x: usize,
4354
}
4455

45-
/// By default, deriving with Reflect assumes the type is a "struct". You can tell reflect to treat
46-
/// your type as a "value type" by using the `reflect_value` attribute instead of `reflect`. It is
47-
/// generally a good idea to implement (and reflect) the `PartialEq`, `Serialize`, and `Deserialize`
48-
/// traits on `reflect_value` types to ensure that these values behave as expected when nested
49-
/// underneath Reflect-ed structs.
56+
/// By default, deriving with Reflect assumes the type is either a "struct" or an "enum".
57+
/// You can tell reflect to treat your type instead as a "value type" by using the `reflect_value`
58+
/// attribute in place of `reflect`. It is generally a good idea to implement (and reflect)
59+
/// the `PartialEq`, `Serialize`, and `Deserialize` traits on `reflect_value` types to ensure
60+
/// that these values behave as expected when nested underneath Reflect-ed structs.
5061
#[derive(Reflect, Copy, Clone, PartialEq, Serialize, Deserialize)]
5162
#[reflect_value(PartialEq, Serialize, Deserialize)]
52-
pub enum E {
63+
pub enum F {
5364
X,
5465
Y,
5566
}
@@ -83,7 +94,7 @@ fn setup() {
8394
// arity 12 or less.
8495
ReflectRef::Tuple(_) => {}
8596
// `Enum` is a trait automatically implemented for enums that derive Reflect. This trait allows you
86-
// to interact list possible variants and interact with the currently active one
97+
// to interact with the current variant and its fields (if it has any)
8798
ReflectRef::Enum(_) => {}
8899
// `List` is a special trait that can be manually implemented (instead of deriving Reflect).
89100
// This exposes "list" operations on your type, such as insertion. `List` is automatically

0 commit comments

Comments
 (0)