transaction_processor/
utils.rs1use types::*;
2
3pub trait IfNotFound {
4 type Target;
5 fn if_not_found<F: FnOnce() -> Self::Target>(self, f: F) -> ProcessResult<Self::Target>;
6}
7
8impl<T> IfNotFound for ProcessResult<T> {
9 type Target = T;
10 fn if_not_found<F: FnOnce() -> T>(self, f: F) -> ProcessResult<T> {
11 match self {
12 Ok(v) => Ok(v),
13 Err(e) => match e {
14 ProcessError::NotFound => Ok(f()),
15 _ => Err(e),
16 },
17 }
18 }
19}
20
21pub fn log(msg: &str) {
22 let msg = msg.as_bytes();
23 unsafe {
24 ::sys::_log(msg.as_ptr(), msg.len());
25 }
26}