]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #37326 - SimonSapin:from-cow, r=alexcrichton
authorbors <bors@rust-lang.org>
Sun, 23 Oct 2016 02:47:05 +0000 (19:47 -0700)
committerGitHub <noreply@github.com>
Sun, 23 Oct 2016 02:47:05 +0000 (19:47 -0700)
Implement `From<Cow<str>> for String` and `From<Cow<[T]>> for Vec<T>`.

Motivation: the `selectors` crate is generic over a string type, in order to support all of `String`,  `string_cache::Atom`, and `gecko_string_cache::Atom`. Multiple trait bounds are used for the various operations done with these strings. One of these operations is creating a string (as efficiently as possible, re-using an existing memory allocation if possible) from `Cow<str>`.

The `std::convert::From` trait seems natural for this, but the relevant implementation was missing before this PR. To work around this I’ve added a `FromCowStr` trait in `selectors`, but with trait coherence that means one of `selectors` or `string_cache` needs to depend on the other to implement this trait. Using a trait from `std` would solve this.

The `Vec<T>` implementation is just added for consistency. I also tried a more general `impl<'a, O, B: ?Sized + ToOwned<Owned=O>> From<Cow<'a, B>> for O`, but (the compiler thinks?) it conflicts with `From<T> for T` the impl (after moving all of `collections::borrow` into `core::borrow` to work around trait coherence).

1  2 
src/libcollections/vec.rs

Simple merge