Ah, I think I see. I was expecting that after the deref trait lands, that a
type like Gc<T> would transparently implement all of the traits that T
implemented. I guess that is not the case. So, if you want to pass the
pointer to a function that expects an instance of one of the traits
implemented by T, you'll have to call borrow() to get a reference and then
pass that reference. However, if you just want to call a method on the
smart-pointer, you can use "." to invoke the method. Is my understanding
correct?

Is there are particular reason that Rust doesn't autogenerate boilerplate
impls like this one? This seems like something that would be fairly
straightforward to do. Impls for ~Trait objects also seem like they could
be auto-generated. Does doing the auto-generation cause the binary size to
explode? Is there some other issue? Or is it just a case of no one having
had time to get around to it yet?

Also, Is there a reason why:

impl <'a, R: Reader> Reader for &'a mut R {
    fn read(&mut self, out: &mut [u8]) -> IoResult<uint> { self.read(out) }
}

doesn't currently exist in the standard library? Would a pull request to
add it make sense?

Thanks!
-Palmer Cox



On Mon, Feb 3, 2014 at 11:04 PM, Bill Myers <[email protected]> wrote:

> I don't think so, because the fact that the particular instance of T
> implements the Deref trait cannot have any effect on the decorator code,
> since it's not in the bounds for T.
>
> What instead would work is to change the language so that if type Type
> implements Trait and all Trait methods take &self or &mut self (as opposed
> to by value self or ~self), then an implementation of Trait for &'a mut
> Type is automatically generated (with the obvious implementation).
>
> Likewise if all Trait methods take &self, then an implementation of Trait
> for &'a Type is also automatically generated.
>
> Then what you want to do will just work without the need of any wrapper or
> special syntax.
>
> One could then, as an additional step, automatically generate an
> implementation of Trait for MutDeref<Type> if Trait is implemented by &mut
> Type (possibly due to the above technique), but this would not be required
> for the example.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to