From 9a7b789c3717146ca3ce3fca1eb23fa3a239f0fb Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 12 Mar 2017 15:04:32 -0400 Subject: [PATCH 1/5] Add doc example for `OsStr::to_os_string`. --- src/libstd/ffi/os_str.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 41bdd9c51d458..3914f398961e4 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -398,6 +398,16 @@ impl OsStr { /// Copies the slice into an owned [`OsString`]. /// /// [`OsString`]: struct.OsString.html + /// + /// # Examples + /// + /// ``` + /// use std::ffi::{OsStr, OsString}; + /// + /// let os_str = OsStr::new("foo"); + /// let os_string = os_str.to_os_string(); + /// assert_eq!(os_string, OsString::from("foo")); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn to_os_string(&self) -> OsString { OsString { inner: self.inner.to_owned() } From 4d57d92f071d24a4c189cc8aef897be25bcd9d55 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 12 Mar 2017 16:21:34 -0400 Subject: [PATCH 2/5] Add doc example for `OsString::reserve`. --- src/libstd/ffi/os_str.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 3914f398961e4..bdd8ce5e6d854 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -188,6 +188,16 @@ impl OsString { /// in the given `OsString`. /// /// The collection may reserve more space to avoid frequent reallocations. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::OsString; + /// + /// let mut s = OsString::new(); + /// s.reserve(10); + /// assert!(s.capacity() >= 10); + /// ``` #[stable(feature = "osstring_simple_functions", since = "1.9.0")] pub fn reserve(&mut self, additional: usize) { self.inner.reserve(additional) From 5537955b1747f8f8c873cf7681ec8a497404e730 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 12 Mar 2017 16:21:58 -0400 Subject: [PATCH 3/5] Add doc example for `OsString::reserve_exact`. --- src/libstd/ffi/os_str.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index bdd8ce5e6d854..d960d76146fe9 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -210,6 +210,16 @@ impl OsString { /// Note that the allocator may give the collection more space than it /// requests. Therefore capacity can not be relied upon to be precisely /// minimal. Prefer reserve if future insertions are expected. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::OsString; + /// + /// let mut s = OsString::new(); + /// s.reserve_exact(10); + /// assert!(s.capacity() >= 10); + /// ``` #[stable(feature = "osstring_simple_functions", since = "1.9.0")] pub fn reserve_exact(&mut self, additional: usize) { self.inner.reserve_exact(additional) From bda57dbc059a15222173b40a5e4d7e5579adcfec Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 12 Mar 2017 16:22:12 -0400 Subject: [PATCH 4/5] Add doc example for `OsString::shrink_to_fit`. --- src/libstd/ffi/os_str.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index d960d76146fe9..9da6eca34086e 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -226,6 +226,22 @@ impl OsString { } /// Shrinks the capacity of the `OsString` to match its length. + /// + /// # Examples + /// + /// ``` + /// #![feature(osstring_shrink_to_fit)] + /// + /// use std::ffi::OsString; + /// + /// let mut s = OsString::from("foo"); + /// + /// s.reserve(100); + /// assert!(s.capacity() >= 100); + /// + /// s.shrink_to_fit(); + /// assert_eq!(3, s.capacity()); + /// ``` #[unstable(feature = "osstring_shrink_to_fit", issue = "40421")] pub fn shrink_to_fit(&mut self) { self.inner.shrink_to_fit() From 6adbbfc6ba8786ea91e1051ea14d64a91839f5b5 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 12 Mar 2017 16:22:29 -0400 Subject: [PATCH 5/5] Add doc example for `OsString::into_boxed_os_str`. --- src/libstd/ffi/os_str.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 9da6eca34086e..b0f79f9a395a6 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -248,6 +248,18 @@ impl OsString { } /// Converts this `OsString` into a boxed `OsStr`. + /// + /// # Examples + /// + /// ``` + /// #![feature(into_boxed_os_str)] + /// + /// use std::ffi::{OsString, OsStr}; + /// + /// let s = OsString::from("hello"); + /// + /// let b: Box = s.into_boxed_os_str(); + /// ``` #[unstable(feature = "into_boxed_os_str", issue = "0")] pub fn into_boxed_os_str(self) -> Box { unsafe { mem::transmute(self.inner.into_box()) }