Improve Ops API

This commit is contained in:
Andreas Longva 2020-12-21 15:13:31 +01:00
parent fe8592fde1
commit 061024ab1f
1 changed files with 9 additions and 8 deletions

View File

@ -15,10 +15,7 @@ pub enum Op<T> {
impl<T> Op<T> { impl<T> Op<T> {
/// TODO /// TODO
pub fn inner_ref(&self) -> &T { pub fn inner_ref(&self) -> &T {
match self { self.as_ref().unwrap()
Op::NoOp(obj) => &obj,
Op::Transpose(obj) => &obj
}
} }
/// TODO /// TODO
@ -33,10 +30,7 @@ impl<T> Op<T> {
pub fn convert<U>(self) -> Op<U> pub fn convert<U>(self) -> Op<U>
where T: Into<U> where T: Into<U>
{ {
match self { self.map_same_op(T::into)
Op::NoOp(obj) => Op::NoOp(obj.into()),
Op::Transpose(obj) => Op::Transpose(obj.into())
}
} }
/// TODO /// TODO
@ -47,6 +41,13 @@ impl<T> Op<T> {
Op::Transpose(obj) => Op::Transpose(f(obj)) Op::Transpose(obj) => Op::Transpose(f(obj))
} }
} }
/// TODO
pub fn unwrap(self) -> T {
match self {
Op::NoOp(obj) | Op::Transpose(obj) => obj,
}
}
} }
impl<T> From<T> for Op<T> { impl<T> From<T> for Op<T> {