From 86bad49ec1f787a4f69a77ccffa06e4967d0c796 Mon Sep 17 00:00:00 2001 From: Joshua Horwitz Date: Fri, 3 Mar 2017 01:24:19 -0500 Subject: Issue #39688 - Help people find String::as_bytes() for UTF-8 r? @steveklabnik --- src/libcollections/string.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/libcollections') diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 4979107ccad..43323676ab4 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -433,6 +433,10 @@ impl String { /// /// [`str::from_utf8()`]: ../../std/str/fn.from_utf8.html /// + /// The inverse of this method is [`as_bytes`]. + /// + /// [`as_bytes`]: #method.as_bytes + /// /// # Errors /// /// Returns `Err` if the slice is not UTF-8 with a description as to why the @@ -979,6 +983,10 @@ impl String { /// Returns a byte slice of this `String`'s contents. /// + /// The inverse of this method is [`from_utf8`]. + /// + /// [`from_utf8`]: #method.from_utf8 + /// /// # Examples /// /// Basic usage: -- cgit 1.4.1-3-g733a5 From df617195f06c27821803acc87e0b1b0dd288799a Mon Sep 17 00:00:00 2001 From: madseagames Date: Sat, 3 Dec 2016 12:47:27 -0400 Subject: Added remove_from to vec.rs --- src/libcollections/vec.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/libcollections') diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 3134e3c2ce1..d38c9f6e1cf 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1335,6 +1335,27 @@ impl Vec { pub fn dedup(&mut self) { self.dedup_by(|a, b| a == b) } + + /// Removes the first instance of `item` from the vector if the item exists. + /// + /// # Examples + /// + /// ``` + ///# #![feature(vec_remove_item)] + /// let mut vec = vec![1, 2, 3, 1]; + /// + /// vec.remove_item(&1); + /// + /// assert_eq!(vec, vec![2, 3, 1]); + /// ``` + #[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")] + pub fn remove_item(&mut self, item: &T) -> Option { + let pos = match self.iter().position(|x| *x == *item) { + Some(x) => x, + None => return None, + }; + Some(self.remove(pos)) + } } //////////////////////////////////////////////////////////////////////////////// -- cgit 1.4.1-3-g733a5 From f3a2f90c88c9d890b67955f0b88def40ce372914 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 8 Mar 2017 00:06:09 +0100 Subject: Document why `str.to_{lower,upper}case` return `String` Fixes #39201. --- src/libcollections/str.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/libcollections') diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 87315fff0a0..e27c4577344 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1646,6 +1646,10 @@ impl str { /// 'Lowercase' is defined according to the terms of the Unicode Derived Core Property /// `Lowercase`. /// + /// Since some characters can expand into multiple characters when changing + /// the case, this function returns a [`String`] instead of modifying the + /// parameter in-place. + /// /// [`String`]: string/struct.String.html /// /// # Examples @@ -1718,6 +1722,10 @@ impl str { /// 'Uppercase' is defined according to the terms of the Unicode Derived Core Property /// `Uppercase`. /// + /// Since some characters can expand into multiple characters when changing + /// the case, this function returns a [`String`] instead of modifying the + /// parameter in-place. + /// /// [`String`]: string/struct.String.html /// /// # Examples -- cgit 1.4.1-3-g733a5