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 {
168168 }
169169}
170170
171+ impl From < NonEmptyString > for String {
172+ fn from ( value : NonEmptyString ) -> Self {
173+ value. 0
174+ }
175+ }
176+
171177#[ cfg( test) ]
172178mod tests {
173179 use super :: * ;
@@ -222,14 +228,21 @@ mod tests {
222228
223229 #[ test]
224230 fn from_str_works ( ) {
225- let empty_str = "" ;
226231 let valid_str = "string" ;
227232
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" ) ;
230234
231235 let non_empty_string = NonEmptyString :: from_str ( valid_str) . unwrap ( ) ;
232236 assert_eq ! ( non_empty_string. as_str( ) , valid_str) ;
233237 assert_eq ! ( non_empty_string, valid_str. parse( ) . unwrap( ) ) ;
234238 }
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+ }
235248}
You can’t perform that action at this time.
0 commit comments