File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use std::hash::{Hash, Hasher};
5
5
use std:: ptr;
6
6
use std:: ops:: { Deref , DerefMut } ;
7
7
use std:: str;
8
+ use std:: str:: FromStr ;
8
9
use std:: str:: Utf8Error ;
9
10
use std:: slice;
10
11
@@ -507,6 +508,16 @@ impl<A> Ord for ArrayString<A>
507
508
}
508
509
}
509
510
511
+ impl < A > FromStr for ArrayString < A >
512
+ where A : Array < Item =u8 > + Copy
513
+ {
514
+ type Err = CapacityError ;
515
+
516
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
517
+ Self :: from ( s) . map_err ( CapacityError :: simplify)
518
+ }
519
+ }
520
+
510
521
#[ cfg( feature="serde-1" ) ]
511
522
/// Requires crate feature `"serde-1"`
512
523
impl < A > Serialize for ArrayString < A >
Original file line number Diff line number Diff line change @@ -487,6 +487,14 @@ fn test_string_from() {
487
487
assert_eq ! ( u. len( ) , text. len( ) ) ;
488
488
}
489
489
490
+ #[ test]
491
+ fn test_string_parse_from_str ( ) {
492
+ let text = "hello world" ;
493
+ let u: ArrayString < [ _ ; 11 ] > = text. parse ( ) . unwrap ( ) ;
494
+ assert_eq ! ( & u, text) ;
495
+ assert_eq ! ( u. len( ) , text. len( ) ) ;
496
+ }
497
+
490
498
#[ test]
491
499
fn test_string_from_bytes ( ) {
492
500
let text = "hello world" ;
You can’t perform that action at this time.
0 commit comments