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:
Aleksei Voronov
2018-12-23 12:50:29 +01:00
parent cffdb4602a
commit 9207e7442f
2 changed files with 19 additions and 0 deletions
+8
View File
@@ -487,6 +487,14 @@ fn test_string_from() {
assert_eq!(u.len(), text.len());
}
#[test]
fn test_string_parse_from_str() {
let text = "hello world";
let u: ArrayString<[_; 11]> = text.parse().unwrap();
assert_eq!(&u, text);
assert_eq!(u.len(), text.len());
}
#[test]
fn test_string_from_bytes() {
let text = "hello world";