File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,12 @@ impl FromStr for NonEmptyString {
168
168
}
169
169
}
170
170
171
+ impl From < NonEmptyString > for String {
172
+ fn from ( value : NonEmptyString ) -> Self {
173
+ value. 0
174
+ }
175
+ }
176
+
171
177
#[ cfg( test) ]
172
178
mod tests {
173
179
use super :: * ;
@@ -222,14 +228,21 @@ mod tests {
222
228
223
229
#[ test]
224
230
fn from_str_works ( ) {
225
- let empty_str = "" ;
226
231
let valid_str = "string" ;
227
232
228
- let _non_empty_string =
229
- NonEmptyString :: from_str ( empty_str) . expect_err ( "operation must be failed" ) ;
233
+ let _non_empty_string = NonEmptyString :: from_str ( "" ) . expect_err ( "operation must be failed" ) ;
230
234
231
235
let non_empty_string = NonEmptyString :: from_str ( valid_str) . unwrap ( ) ;
232
236
assert_eq ! ( non_empty_string. as_str( ) , valid_str) ;
233
237
assert_eq ! ( non_empty_string, valid_str. parse( ) . unwrap( ) ) ;
234
238
}
239
+
240
+ #[ test]
241
+ fn into_works ( ) {
242
+ let non_empty_string = NonEmptyString :: new ( "string" . to_string ( ) ) . unwrap ( ) ;
243
+ let _string: String = non_empty_string. into ( ) ;
244
+
245
+ let non_empty_string = NonEmptyString :: new ( "string" . to_string ( ) ) . unwrap ( ) ;
246
+ let _string = String :: from ( non_empty_string) ;
247
+ }
235
248
}
You can’t perform that action at this time.
0 commit comments