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
/// Implements the following traits:
///
/// * `AsRef<object::Base>`
/// * `AsMut<object::Base>`
/// * `Object`
///
/// # Examples
///
/// Creating a wrapper around a named field.
///
/// ```rust
/// #[macro_use]
/// extern crate three;
///
/// three_object!(MyStruct::mesh);
/// struct MyStruct {
///     mesh: three::Mesh,
/// }
/// # fn main() {}
/// ```
///
/// If the field parameter is omitted then the field name defaults to `object`.
///
/// ```rust
/// #[macro_use]
/// extern crate three;
///
/// // Equivalent to `three_object!(MyStruct::object);`
/// three_object!(MyStruct);
/// struct MyStruct {
///     object: three::Mesh,
/// }
/// # fn main() {}
/// ```
///
/// [`object::Base`]: object/struct.Base.html
macro_rules! three_object {
    ($name:ident::$field:ident) => {
        impl AsRef<$crate::object::Base> for $name {
            fn as_ref(&self) -> &$crate::object::Base {
                &self.$field
            }
        }

        impl $crate::Object for $name {}
    };
}