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
extern crate alga;
#[macro_use]
extern crate gfx;
extern crate gfx_device_gl;
extern crate gfx_window_glutin;
extern crate glutin;
extern crate image;
#[macro_use]
extern crate lazy_static;
extern crate nalgebra;
extern crate num;
extern crate rand;
extern crate winit;

pub mod clamp;
pub mod cube;
pub mod event;
pub mod math;
pub mod mesh;
pub mod render;
pub mod resource;

pub trait OptionExt<T> {
    fn and_if<F>(self, f: F) -> Self where F: Fn(&T) -> bool;
}

impl<T> OptionExt<T> for Option<T> {
    fn and_if<F>(mut self, f: F) -> Self
        where F: Fn(&T) -> bool
    {
        match self.take() {
            Some(value) => if f(&value) { Some(value) } else { None },
            _ => None,
        }
    }
}