Implement FromStr for ArrayString
This is very useful for generic code that may want to parse arbitrary input string into arbitrary other types. Limitations of the FromStr trait don't allow us to keep the original string slice inside the CapacityError, unfortunately.
This commit is contained in:
@@ -5,6 +5,7 @@ use std::hash::{Hash, Hasher};
|
||||
use std::ptr;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::str;
|
||||
use std::str::FromStr;
|
||||
use std::str::Utf8Error;
|
||||
use std::slice;
|
||||
|
||||
@@ -507,6 +508,16 @@ impl<A> Ord for ArrayString<A>
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> FromStr for ArrayString<A>
|
||||
where A: Array<Item=u8> + Copy
|
||||
{
|
||||
type Err = CapacityError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Self::from(s).map_err(CapacityError::simplify)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="serde-1")]
|
||||
/// Requires crate feature `"serde-1"`
|
||||
impl<A> Serialize for ArrayString<A>
|
||||
|
||||
Reference in New Issue
Block a user