1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::prelude::*;

pub trait Missing {
    fn missing<T: Primitive>(&self, branch: &BranchId) -> Result<T, Error>;
}

pub struct ErrOnMissing;
impl Missing for ErrOnMissing {
    #[inline(always)]
    fn missing<T: Primitive>(&self, branch: &BranchId) -> Result<T, Error> {
        Err(Error::Missing {
            branch: format!("{:?}", branch), // TODO: This no longer carries the whole parent name, which would be desirable
            id: T::id(),
        })
    }
}

pub struct DefaultOnMissing;
impl Missing for DefaultOnMissing {
    #[inline(always)]
    fn missing<T: Default>(&self, _branch: &BranchId) -> Result<T, Error> {
        Ok(T::default())
    }
}