From 28f556adb1bc54a5d1434d68fd42d5b1c3034974 Mon Sep 17 00:00:00 2001 From: jcesar Date: Tue, 22 Mar 2016 01:59:12 +0800 Subject: [PATCH 1/2] Add Default implementation for OsString #32385w --- src/libstd/ffi/os_str.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 46f2d3a64181b..24a157012d986 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -397,6 +397,15 @@ impl_cmp!(Cow<'a, OsStr>, OsStr); impl_cmp!(Cow<'a, OsStr>, &'b OsStr); impl_cmp!(Cow<'a, OsStr>, OsString); +#[stable(feature = "os_str_default", since = "1.9.0")] +impl Default for OsString { + #[inline] + fn default() -> OsString { + OsString::new() + } +} + + #[stable(feature = "rust1", since = "1.0.0")] impl Hash for OsStr { #[inline] @@ -577,4 +586,10 @@ mod tests { os_string.clear(); assert_eq!(0, os_string.len()); } + + #[test] + fn test_os_str_default(){ + let os_str = Default::default(); + assert!(os_str.is_empty()) + } } From 24b5fd95c9949a5109a6c430f961a1f1c361d52e Mon Sep 17 00:00:00 2001 From: jcesar Date: Tue, 22 Mar 2016 02:04:56 +0800 Subject: [PATCH 2/2] Remove trailing whitespace --- src/libstd/ffi/os_str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 24a157012d986..f219e4d96c3cd 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -586,7 +586,7 @@ mod tests { os_string.clear(); assert_eq!(0, os_string.len()); } - + #[test] fn test_os_str_default(){ let os_str = Default::default();