about summary refs log tree commit diff
path: root/src/test/run-pass/thinlto
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2016-10-21 16:51:59 +0200
committerSimon Sapin <simon.sapin@exyr.org>2016-10-21 17:42:29 +0200
commit7e603d4e3b2551608a225e115da4e83559b94761 (patch)
tree9bb200cfcbad55de7f3ed5bc539d96fa7dc103f0 /src/test/run-pass/thinlto
parentda5b6467c33f7f86b4964b08b37726f7611a8f0c (diff)
downloadrust-7e603d4e3b2551608a225e115da4e83559b94761.tar.gz
rust-7e603d4e3b2551608a225e115da4e83559b94761.zip
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).
Diffstat (limited to 'src/test/run-pass/thinlto')
0 files changed, 0 insertions, 0 deletions