@@ -173,6 +173,14 @@ impl ops::Deref for OsString {
173
173
}
174
174
}
175
175
176
+ #[ stable( feature = "osstring_default" , since = "1.9.0" ) ]
177
+ impl Default for OsString {
178
+ #[ inline]
179
+ fn default ( ) -> OsString {
180
+ OsString :: new ( )
181
+ }
182
+ }
183
+
176
184
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
177
185
impl Debug for OsString {
178
186
fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
@@ -302,6 +310,14 @@ impl OsStr {
302
310
}
303
311
}
304
312
313
+ #[ stable( feature = "osstring_default" , since = "1.9.0" ) ]
314
+ impl < ' a > Default for & ' a OsStr {
315
+ #[ inline]
316
+ fn default ( ) -> & ' a OsStr {
317
+ OsStr :: new ( "" )
318
+ }
319
+ }
320
+
305
321
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
306
322
impl PartialEq for OsStr {
307
323
fn eq ( & self , other : & OsStr ) -> bool {
@@ -554,6 +570,12 @@ mod tests {
554
570
assert ! ( os_string. capacity( ) >= 33 )
555
571
}
556
572
573
+ #[ test]
574
+ fn test_os_string_default ( ) {
575
+ let os_string: OsString = Default :: default ( ) ;
576
+ assert_eq ! ( "" , & os_string) ;
577
+ }
578
+
557
579
#[ test]
558
580
fn test_os_str_is_empty ( ) {
559
581
let mut os_string = OsString :: new ( ) ;
@@ -577,4 +599,10 @@ mod tests {
577
599
os_string. clear ( ) ;
578
600
assert_eq ! ( 0 , os_string. len( ) ) ;
579
601
}
602
+
603
+ #[ test]
604
+ fn test_os_str_default ( ) {
605
+ let os_str: & OsStr = Default :: default ( ) ;
606
+ assert_eq ! ( "" , os_str) ;
607
+ }
580
608
}
0 commit comments