From 061024ab1fe63807a3c35771a3d1b062b27c40b0 Mon Sep 17 00:00:00 2001 From: Andreas Longva Date: Mon, 21 Dec 2020 15:13:31 +0100 Subject: [PATCH] Improve Ops API --- nalgebra-sparse/src/ops/mod.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/nalgebra-sparse/src/ops/mod.rs b/nalgebra-sparse/src/ops/mod.rs index 14a18dc1..80fde80d 100644 --- a/nalgebra-sparse/src/ops/mod.rs +++ b/nalgebra-sparse/src/ops/mod.rs @@ -15,10 +15,7 @@ pub enum Op { impl Op { /// TODO pub fn inner_ref(&self) -> &T { - match self { - Op::NoOp(obj) => &obj, - Op::Transpose(obj) => &obj - } + self.as_ref().unwrap() } /// TODO @@ -33,10 +30,7 @@ impl Op { pub fn convert(self) -> Op where T: Into { - match self { - Op::NoOp(obj) => Op::NoOp(obj.into()), - Op::Transpose(obj) => Op::Transpose(obj.into()) - } + self.map_same_op(T::into) } /// TODO @@ -47,6 +41,13 @@ impl Op { Op::Transpose(obj) => Op::Transpose(f(obj)) } } + + /// TODO + pub fn unwrap(self) -> T { + match self { + Op::NoOp(obj) | Op::Transpose(obj) => obj, + } + } } impl From for Op {