File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ mod test_readme {
12
12
13
13
use delegate:: delegate;
14
14
use std:: fmt:: Display ;
15
+ use std:: ops:: Deref ;
15
16
16
17
#[ cfg( feature = "serde" ) ]
17
18
mod serde_support;
@@ -128,6 +129,14 @@ impl AsRef<String> for NonEmptyString {
128
129
}
129
130
}
130
131
132
+ impl Deref for NonEmptyString {
133
+ type Target = str ;
134
+
135
+ fn deref ( & self ) -> & Self :: Target {
136
+ self . 0 . deref ( )
137
+ }
138
+ }
139
+
131
140
impl < ' s > TryFrom < & ' s str > for NonEmptyString {
132
141
type Error = & ' s str ;
133
142
@@ -205,4 +214,17 @@ mod tests {
205
214
println ! ( "{}" , & str ) ;
206
215
assert_eq ! ( String :: from( "string" ) , str . to_string( ) )
207
216
}
217
+
218
+
219
+ fn print_str ( str : & str ) {
220
+ println ! ( "{str}" )
221
+ }
222
+
223
+ #[ test]
224
+ fn deref_works ( ) {
225
+ let str = "My String" ;
226
+ let non_empty_string = NonEmptyString :: try_from ( str) . unwrap ( ) ;
227
+ print_str ( & non_empty_string) ;
228
+ assert_eq ! ( str , non_empty_string. deref( ) ) ;
229
+ }
208
230
}
You can’t perform that action at this time.
0 commit comments