use crate::num::basic::unsigneds::PrimitiveUnsigned;
use crate::unsigned_vector::UnsignedVector;
use alloc::vec::Vec;
use core::str::FromStr;
impl<T: PrimitiveUnsigned> FromStr for UnsignedVector<T> {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
let inner = s
.strip_prefix('(')
.and_then(|s| s.strip_suffix(')'))
.ok_or(())?;
if inner.is_empty() {
return Ok(Self {
elements: Vec::new(),
});
}
Ok(Self {
elements: inner
.split(", ")
.map(|x| T::from_str(x).map_err(|_| ()))
.collect::<Result<_, _>>()?,
})
}
}