[rust-dev] PipeStream.by_ref() - Multiple applicable methods problem

Alex Crichton alex at crichton.co
Wed Apr 30 09:13:35 PDT 2014


Oddly enough, that was the first thing I jumped to as well! I think
that type inference like that doesn't drive method selection, which is
why it ended up not working out.

On Wed, Apr 30, 2014 at 3:54 AM, Michael Neumann <mneumann at ntecs.de> wrote:
>
>
> Am 29.04.2014 22:51, schrieb Alex Crichton:
>
>> The by_ref() method exists on both the Reader and the Writer trait,
>> and you're working with a stream which implements both Reader and
>> Writer (hence the confusion by the compiler).
>>
>> You could work around it with something like:
>>
>>      fn rdr<'a, T: Reader>(t: &'a mut T) -> RefReader<'a, T> {
>>          t.by_ref()
>>      }
>>
>> Eventually, with UFCS, you'll be able to do something like:
>>
>>      let rdr = Reader::by_ref(&mut inp);
>>
>> (hopefully soon!)
>
> Thanks so much!  This works!
>
> Actually I was trying to explicitly specify the type as in:
>
>   let rdr: RefReader<PipeStream> = t.by_ref();
>
> and was wondering why it failed.
>
> Regards,
>
>   Michael


More information about the Rust-dev mailing list