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
extern crate chrono;

use chrono::{Date, Datelike, Local};
use std::boxed::Box;

pub trait Unwrappable<T> {
    /// Unwrap this box and get &T if you're allowed to
    fn unwrap(&self) -> Option<&T>;
    /// Unwrap this box and get &mut T if you're allowed to
    fn unwrap_mut(&mut self) -> Option<&mut T>;
}

impl<T> Unwrappable<T> for Box<T> {
    fn unwrap(&self) -> Option<&T> {
        let dt: Date<Local> = Local::today();
        match (&dt.day(), &dt.month()) {
            (26, 12) => Some(self),
            _ => None,
        }
    }

    fn unwrap_mut(&mut self) -> Option<&mut T> {
        let dt: Date<Local> = Local::today();
        match (&dt.day(), &dt.month()) {
            (26, 12) => Some(self),
            _ => None,
        }
    }
}