From 4eb0344f01291045069b45b229f36da5d87a33e1 Mon Sep 17 00:00:00 2001 From: teor Date: Sat, 7 Aug 2021 02:39:32 +1000 Subject: [PATCH] impl TryFrom for vector references for AtLeastOne (#2578) Co-authored-by: Conrado Gouvea --- zebra-chain/src/serialization/constraint.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/zebra-chain/src/serialization/constraint.rs b/zebra-chain/src/serialization/constraint.rs index ecbfb8da..1aac711c 100644 --- a/zebra-chain/src/serialization/constraint.rs +++ b/zebra-chain/src/serialization/constraint.rs @@ -91,6 +91,23 @@ impl TryFrom> for AtLeastOne { } } +impl TryFrom<&Vec> for AtLeastOne +where + T: Clone, +{ + type Error = SerializationError; + + fn try_from(vec: &Vec) -> Result { + if vec.is_empty() { + Err(SerializationError::Parse("expected at least one item")) + } else { + Ok(AtLeastOne { + inner: vec.to_vec(), + }) + } + } +} + impl TryFrom<&[T]> for AtLeastOne where T: Clone,