Skip to content

Commit

Permalink
Fix up example
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Jun 11, 2022
1 parent 845b16e commit 43d654c
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions examples/reflection/reflection_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,43 @@ pub struct A {
z: HashMap<String, f32>,
}

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

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

/// Deriving reflect on an enum will implement the `Reflect` and `Enum` traits
#[derive(Reflect)]
pub enum D {
A,
B(usize),
C {
foo: f32,
bar: bool
}
}

/// Reflect has "built in" support for some common traits like `PartialEq`, `Hash`, and `Serialize`.
/// These are exposed via methods like `Reflect::hash()`, `Reflect::partial_eq()`, and
/// `Reflect::serialize()`. You can force these implementations to use the actual trait
/// These are exposed via methods like `Reflect::reflect_hash()`, `Reflect::reflect_partial_eq()`, and
/// `Reflect::serializable()`. You can force these implementations to use the actual trait
/// implementations (instead of their defaults) like this:
#[derive(Reflect, Hash, Serialize, PartialEq)]
#[reflect(Hash, Serialize, PartialEq)]
pub struct D {
pub struct E {
x: usize,
}

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

0 comments on commit 43d654c

Please sign in to comment.