Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ impl ops::Deref for OsString {
}
}

#[stable(feature = "osstring_default", since = "1.9.0")]
impl Default for OsString {
#[inline]
fn default() -> OsString {
OsString::new()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for OsString {
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
Expand Down Expand Up @@ -302,6 +310,14 @@ impl OsStr {
}
}

#[stable(feature = "osstring_default", since = "1.9.0")]
impl<'a> Default for &'a OsStr {
#[inline]
fn default() -> &'a OsStr {
OsStr::new("")
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq for OsStr {
fn eq(&self, other: &OsStr) -> bool {
Expand Down Expand Up @@ -554,6 +570,12 @@ mod tests {
assert!(os_string.capacity() >= 33)
}

#[test]
fn test_os_string_default() {
let os_string: OsString = Default::default();
assert_eq!("", &os_string);
}

#[test]
fn test_os_str_is_empty() {
let mut os_string = OsString::new();
Expand All @@ -577,4 +599,10 @@ mod tests {
os_string.clear();
assert_eq!(0, os_string.len());
}

#[test]
fn test_os_str_default() {
let os_str: &OsStr = Default::default();
assert_eq!("", os_str);
}
}