These are chat archives for rust-lang/rust

31st
Mar 2016
John C F
@critiqjo
Mar 31 2016 12:06
I recently noticed that IntoCow is deprecated. Is it going to be replaced by Into<Cow<..>>? Why is it not already done for strings (I believe it's not possible for vectors since it has type parameters?)? Any idea when it will be implemented?
Vladimir Matveev
@netvl
Mar 31 2016 12:07
I believe that Into<Cow<[T]>> would be the cow for vector
Into<Cow<str>> for strings
Erik Hedvall
@Ogeon
Mar 31 2016 12:10
Cow<'a, str> implements both From<&'a str> and From<String>, so it's already done.
John C F
@critiqjo
Mar 31 2016 12:10

I believe that Into<Cow<[T]>> would be the cow for vector

I don't think there is such an implementation right now...

Erik Hedvall
@Ogeon
Mar 31 2016 12:11
Doing it for vectors and slices may cause coherence problems, but I don't know for sure
John C F
@critiqjo
Mar 31 2016 12:11

Cow<'a, str> implements both From<&'a str> and From<String>, so it's already done.

The thing is I'm trying to write a function which can take both &str and String and return a Cow

Erik Hedvall
@Ogeon
Mar 31 2016 12:12
Then you should be able to take a T: Into<Cow<'a, str>>.
Vladimir Matveev
@netvl
Mar 31 2016 12:12
@critiqjo indeed, you’re right, there is no Into<Cow<[T]>> implementation, that’s strange
I was under impression it was there
John C F
@critiqjo
Mar 31 2016 12:16
Oh! But Into<Cow<'a, str>> actually exists, but I couldn't find it in the docs at all... Thanks everyone...
Erik Hedvall
@Ogeon
Mar 31 2016 12:18
Into<T> is blanket implemented for U where T: From<U>, so it's always there if T: From<U> is there.
John C F
@critiqjo
Mar 31 2016 12:34

Ahh... Thanks a lot!

There should be a way to list all implementations (incl. auto-traits, at least the global ones from std) at one place...

Erik Hedvall
@Ogeon
Mar 31 2016 12:36
Would be nice, but could also become combinatorial monsters