File tree 1 file changed +22
-1
lines changed 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 37
37
extern crate alloc;
38
38
39
39
use alloc:: { boxed:: Box , string:: String , vec:: Vec } ;
40
+ use core:: convert:: Infallible ;
41
+ use core:: str:: FromStr ;
40
42
use core:: {
41
43
any,
42
44
fmt:: { self , Debug } ,
43
45
} ;
44
-
45
46
use zeroize:: { Zeroize , ZeroizeOnDrop } ;
46
47
47
48
#[ cfg( feature = "serde" ) ]
@@ -225,6 +226,14 @@ impl From<&str> for SecretString {
225
226
}
226
227
}
227
228
229
+ impl FromStr for SecretString {
230
+ type Err = Infallible ;
231
+
232
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
233
+ Ok ( Self :: from ( s) )
234
+ }
235
+ }
236
+
228
237
impl Clone for SecretString {
229
238
fn clone ( & self ) -> Self {
230
239
SecretBox {
@@ -323,3 +332,15 @@ where
323
332
self . expose_secret ( ) . serialize ( serializer)
324
333
}
325
334
}
335
+
336
+ #[ cfg( test) ]
337
+ mod tests {
338
+ use crate :: { ExposeSecret , SecretString } ;
339
+ use core:: str:: FromStr ;
340
+
341
+ #[ test]
342
+ fn test_secret_string_from_str ( ) {
343
+ let secret = SecretString :: from_str ( "test" ) . unwrap ( ) ;
344
+ assert_eq ! ( secret. expose_secret( ) , "test" ) ;
345
+ }
346
+ }
You can’t perform that action at this time.
0 commit comments