impl TryFrom for vector references for AtLeastOne (#2578)

Co-authored-by: Conrado Gouvea <conrado@zfnd.org>
This commit is contained in:
teor 2021-08-07 02:39:32 +10:00 committed by GitHub
parent 0cc773f4b8
commit 4eb0344f01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -91,6 +91,23 @@ impl<T> TryFrom<Vec<T>> for AtLeastOne<T> {
}
}
impl<T> TryFrom<&Vec<T>> for AtLeastOne<T>
where
T: Clone,
{
type Error = SerializationError;
fn try_from(vec: &Vec<T>) -> Result<Self, Self::Error> {
if vec.is_empty() {
Err(SerializationError::Parse("expected at least one item"))
} else {
Ok(AtLeastOne {
inner: vec.to_vec(),
})
}
}
}
impl<T> TryFrom<&[T]> for AtLeastOne<T>
where
T: Clone,