typeline_core/utils/
maybe_boxed.rs

1pub trait MaybeBoxed<T> {
2    fn boxed(self) -> Box<T>;
3    fn base_ref(&self) -> &T;
4    fn base_ref_mut(&mut self) -> &mut T;
5}
6
7impl<T> MaybeBoxed<T> for Box<T> {
8    fn boxed(self) -> Box<T> {
9        todo!()
10    }
11
12    fn base_ref(&self) -> &T {
13        self
14    }
15
16    fn base_ref_mut(&mut self) -> &mut T {
17        &mut *self
18    }
19}
20impl<T> MaybeBoxed<T> for T {
21    fn boxed(self) -> Box<T> {
22        Box::new(self)
23    }
24
25    fn base_ref(&self) -> &T {
26        self
27    }
28
29    fn base_ref_mut(&mut self) -> &mut T {
30        self
31    }
32}