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
extern crate rand;
#[macro_use]
extern crate memoffset;
#[macro_use]
extern crate lazy_static;
pub mod color;
pub mod color_gradient;
pub mod math;
pub mod numeric_range;
pub mod octree;
pub mod pool;
pub mod rectpack;
pub mod visitor;
pub mod profiler;
#[macro_export]
macro_rules! define_is_as {
($typ:tt : $kind:ident -> ref $result:ty => fn $is:ident, fn $as_ref:ident, fn $as_mut:ident) => {
pub fn $is(&self) -> bool {
match self {
$typ::$kind(_) => true,
_ => false,
}
}
pub fn $as_ref(&self) -> &$result {
match self {
$typ::$kind(ref val) => val,
_ => panic!("Cast to {} failed!", stringify!($kind)),
}
}
pub fn $as_mut(&mut self) -> &mut $result {
match self {
$typ::$kind(ref mut val) => val,
_ => panic!("Cast to {} failed!", stringify!($kind)),
}
}
};
}