clay_core/material/
select.rs

1/// The macro for making a union of materials.
2///
3/// You can read more about the technique [here](https://clay-rs.github.io/knowledge/#objects).
4#[macro_export]
5macro_rules! material_select {
6    ( $Select:ident { $( $Enum:ident ( $Param:ident = $Material:ty ) ),+ $(,)? } ) => {
7        $crate::instance_select!(
8            $Select: $crate::material::Material: $crate::material::MaterialClass {
9                $( $Enum($Param = $Material) ),+
10            }
11        );
12        impl Material for $Select {
13            fn brightness(&self) -> f64 {
14                match self {
15                    $( $Select::$Enum(m) => m.brightness(), )+
16                }
17            }
18        }
19    };
20}
21
22#[cfg(test)]
23mod check {
24    use crate::{
25        material::{
26            Material,
27            test::TestMaterial,
28        },
29        material_select,
30    };
31
32    material_select!(
33        TestSelect {
34            Material1(T1 = TestMaterial<i32>),
35            Material2(T2 = TestMaterial<f32>),
36        }
37    );
38}