From 2adb0a8b49f8c232bbba7793827e366d38859f6c Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Fri, 7 Jul 2023 14:04:57 +0000 Subject: [PATCH] node: some more utility methods on Inner --- src/node/inner.rs | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/node/inner.rs b/src/node/inner.rs index ca298c24..465a666b 100644 --- a/src/node/inner.rs +++ b/src/node/inner.rs @@ -303,7 +303,7 @@ impl, W> Inner { } } -impl Inner, J, Option, W> { +impl Inner, J, X, W> { /// Convert an `Inner, J, W>` to an `Option>`. pub fn transpose(self) -> Option> { Some(match self { @@ -318,7 +318,31 @@ impl Inner, J, Option, W> { Inner::AssertL(c, cmr) => Inner::AssertL(c?, cmr), Inner::AssertR(cmr, c) => Inner::AssertR(cmr, c?), Inner::Pair(cl, cr) => Inner::Pair(cl?, cr?), - Inner::Disconnect(cl, cr) => Inner::Disconnect(cl?, cr?), + Inner::Disconnect(cl, cr) => Inner::Disconnect(cl?, cr), + Inner::Witness(w) => Inner::Witness(w), + Inner::Fail(entropy) => Inner::Fail(entropy), + Inner::Jet(j) => Inner::Jet(j), + Inner::Word(w) => Inner::Word(w), + }) + } +} + +impl Inner, W> { + /// Convert an `Inner, J, W>` to an `Option>`. + pub fn transpose_disconnect(self) -> Option> { + Some(match self { + Inner::Iden => Inner::Iden, + Inner::Unit => Inner::Unit, + Inner::InjL(c) => Inner::InjL(c), + Inner::InjR(c) => Inner::InjR(c), + Inner::Take(c) => Inner::Take(c), + Inner::Drop(c) => Inner::Drop(c), + Inner::Comp(cl, cr) => Inner::Comp(cl, cr), + Inner::Case(cl, cr) => Inner::Case(cl, cr), + Inner::AssertL(c, cmr) => Inner::AssertL(c, cmr), + Inner::AssertR(cmr, c) => Inner::AssertR(cmr, c), + Inner::Pair(cl, cr) => Inner::Pair(cl, cr), + Inner::Disconnect(cl, cr) => Inner::Disconnect(cl, cr?), Inner::Witness(w) => Inner::Witness(w), Inner::Fail(entropy) => Inner::Fail(entropy), Inner::Jet(j) => Inner::Jet(j), @@ -351,7 +375,7 @@ impl Inner> { } } -impl Inner { +impl Inner { /// Copies witness data. /// /// Useful in conjunction with [`Inner::as_ref`] when you don't want to @@ -361,6 +385,16 @@ impl Inner { } } +impl Inner { + /// Copies disconnect data. + /// + /// Useful in conjunction with [`Inner::as_ref`] when you don't want to + /// take a reference to disconnect data. + pub fn copy_disconnect(self) -> Inner { + self.map_disconnect(X::clone) + } +} + impl fmt::Display for Inner { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self {