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
/// 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_export]
macro_rules! three_object {
($name:ident::$field:ident) => {
impl AsRef<$crate::object::Base> for $name {
fn as_ref(&self) -> &$crate::object::Base {
&self.$field.as_ref()
}
}
impl $crate::Object for $name {
type Data = ();
fn resolve_data(&self, _: & $crate::scene::SyncGuard) -> Self::Data {}
}
};
($name:ident) => {
three_object!($name ::object);
}
}
macro_rules! derive_DowncastObject {
($type:ident => $pattern:path) => {
impl ::object::DowncastObject for $type {
fn downcast(object: ::object::ObjectType) -> Option<Self> {
match object {
$pattern (inner) => Some(inner),
_ => None,
}
}
}
}
}