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
use types::*;

pub trait IfNotFound {
    type Target;
    fn if_not_found<F: FnOnce() -> Self::Target>(self, f: F) -> ProcessResult<Self::Target>;
}

impl<T> IfNotFound for ProcessResult<T> {
    type Target = T;
    fn if_not_found<F: FnOnce() -> T>(self, f: F) -> ProcessResult<T> {
        match self {
            Ok(v) => Ok(v),
            Err(e) => match e {
                ProcessError::NotFound => Ok(f()),
                _ => Err(e),
            },
        }
    }
}

pub fn log(msg: &str) {
    let msg = msg.as_bytes();
    unsafe {
        ::sys::_log(msg.as_ptr(), msg.len());
    }
}