From 5a97036b6900ee208f90c52ceadcce606d497e93 Mon Sep 17 00:00:00 2001 From: Clar Charr Date: Sat, 20 May 2017 15:40:53 -0400 Subject: Convert Intos to Froms. --- src/liballoc/string.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 2cb81029f95..c1ef1c2f96c 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2009,9 +2009,9 @@ impl From> for String { } #[stable(feature = "box_from_str", since = "1.18.0")] -impl Into> for String { - fn into(self) -> Box { - self.into_boxed_str() +impl From for Box { + fn from(s: String) -> Box { + s.into_boxed_str() } } -- cgit 1.4.1-3-g733a5 From 0d885efe16899c2dbad2918345c9ede7b83caa7f Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Tue, 13 Jun 2017 00:08:37 +0100 Subject: Update version numbers for From impls --- src/liballoc/string.rs | 2 +- src/libstd/ffi/c_str.rs | 2 +- src/libstd/ffi/os_str.rs | 2 +- src/libstd/path.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index c1ef1c2f96c..02ecb65fa38 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2008,7 +2008,7 @@ impl From> for String { } } -#[stable(feature = "box_from_str", since = "1.18.0")] +#[stable(feature = "box_from_str", since = "1.20.0")] impl From for Box { fn from(s: String) -> Box { s.into_boxed_str() diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 1586e0a4ddb..5f0b11a616e 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -585,7 +585,7 @@ impl From> for CString { } } -#[stable(feature = "box_from_c_string", since = "1.18.0")] +#[stable(feature = "box_from_c_string", since = "1.20.0")] impl From for Box { #[inline] fn from(s: CString) -> Box { diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 3815f986681..3232a51546e 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -542,7 +542,7 @@ impl From> for OsString { } } -#[stable(feature = "box_from_os_string", since = "1.18.0")] +#[stable(feature = "box_from_os_string", since = "1.20.0")] impl From for Box { fn from(s: OsString) -> Box { s.into_boxed_os_str() diff --git a/src/libstd/path.rs b/src/libstd/path.rs index e9bf7b33b8e..7a8c8935394 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1348,7 +1348,7 @@ impl From> for PathBuf { } } -#[stable(feature = "box_from_path_buf", since = "1.18.0")] +#[stable(feature = "box_from_path_buf", since = "1.20.0")] impl From for Box { fn from(p: PathBuf) -> Box { p.into_boxed_path() -- cgit 1.4.1-3-g733a5 From d68c3ab17b6f6c3b71d0531063aec8e64098f59c Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 3 Jul 2017 17:18:01 -0400 Subject: Document unintuitive argument order for Vec::dedup_by relation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When trying to use dedup_by to merge some auxiliary information from removed elements into kept elements, I was surprised to observe that vec.dedup_by(same_bucket) calls same_bucket(a, b) where b appears before a in the vector, and discards a when true is returned. This argument order is probably a bug, but since it has already been stabilized, I guess we should document it as a feature and move on. (Vec::dedup also uses == with this unexpected argument order, but I figure that’s not important since == is expected to be symmetric with no side effects.) Signed-off-by: Anders Kaseorg --- src/liballoc/tests/vec.rs | 5 +++++ src/liballoc/vec.rs | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index fdf453b39cf..17f1229c206 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -274,6 +274,11 @@ fn test_dedup_by() { vec.dedup_by(|a, b| a.eq_ignore_ascii_case(b)); assert_eq!(vec, ["foo", "bar", "baz", "bar"]); + + let mut vec = vec![("foo", 1), ("foo", 2), ("bar", 3), ("bar", 4), ("bar", 5)]; + vec.dedup_by(|a, b| a.0 == b.0 && { b.1 += a.1; true }); + + assert_eq!(vec, [("foo", 3), ("bar", 12)]); } #[test] diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 5d1999a4262..1a5975686df 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -823,7 +823,8 @@ impl Vec { } } - /// Removes consecutive elements in the vector that resolve to the same key. + /// Removes all but the first of consecutive elements in the vector that resolve to the same + /// key. /// /// If the vector is sorted, this removes all duplicates. /// @@ -842,11 +843,13 @@ impl Vec { self.dedup_by(|a, b| key(a) == key(b)) } - /// Removes consecutive elements in the vector according to a predicate. + /// Removes all but the first of consecutive elements in the vector satisfying a given equality + /// relation. /// /// The `same_bucket` function is passed references to two elements from the vector, and - /// returns `true` if the elements compare equal, or `false` if they do not. Only the first - /// of adjacent equal items is kept. + /// returns `true` if the elements compare equal, or `false` if they do not. The elements are + /// passed in opposite order from their order in the vector, so if `same_bucket(a, b)` returns + /// `true`, `a` is removed. /// /// If the vector is sorted, this removes all duplicates. /// -- cgit 1.4.1-3-g733a5