On Sat, Jul 6, 2013 at 10:26 PM, Daniel Micay <[email protected]> wrote:
> On Sat, Jul 6, 2013 at 10:09 PM, Ashish Myles <[email protected]> wrote:
>> Perhaps this was an oversight as the code base has developed
>> organically. But in case it was intentional, I just wanted to check.
>>
>> libstd/to_str.rs defines each of the following impls
>>     impl<'self,A:ToStr> ToStr for &'self [A]
>>     impl<A:ToStr> ToStr for ~[A]
>>     impl<A:ToStr> ToStr for @[A]
>> whereas only the first one seems to be needed to cover all array
>> cases. To test this, I defined an equivalent MyToStr trait, defining
>> only the implementation for &'self [A], and it seemed to work for all
>> the array types. So just to check: is there any particular reason one
>> would want to define all three with identical implementation?
>
> Vectors will coerce to slices, but the traits still need to be defined
> on them for it to work in generic code where you only have a type via
> a generic type parameter.

Oh that's a great point. I have already run multiple times into
struggling to understand the compiler rejection of my code until I
realized that I simply didn't declare the generic type parameter as
having defined the required traits.

I suppose it's lower priority but it would be nice to have the feature
of defining a trait implementation for all three types (&, ~, @)
simultaneously.  Using a private helper function not belonging to any
trait seems to work for now.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to