These are chat archives for rust-lang/rust

4th
Apr 2018
Denis
@mexus
Apr 04 2018 07:32
no problem :)
Dylan DPC
@Dylan-DPC
Apr 04 2018 19:04

who's up for a fun generics problem?
i have a struct:

struct Foo<T: Trait> { 
  pub prop: T
}

and

struct Bar<T: Trait> { 
  pub foo: Foo<T> 
}

also I have:

struct Baz {
 pub foo: Box<Trait>
}

and somewhere down the line in the impl <T>Bar<T> i'm doing :
Box::new(self.foo.prop)
but i get:
the trait bound &T: Trait is not satisfied

Denis
@mexus
Apr 04 2018 19:06
could you prepare a minimal example? on the playground pls :)
Dylan DPC
@Dylan-DPC
Apr 04 2018 19:07
:D
Denis
@mexus
Apr 04 2018 19:17
well i meant https://play.rust-lang.org/ but ok
ya it generated the gist from there :D
Denis
@mexus
Apr 04 2018 19:18
well
Dylan DPC
@Dylan-DPC
Apr 04 2018 19:18
have to go off.. just mention me with whatever you get, will check it in the morning. Thanks
okay tell :D
Denis
@mexus
Apr 04 2018 19:18
if T implements a Trait, it doesn't mean that &T implements it as well
Dylan DPC
@Dylan-DPC
Apr 04 2018 19:18
true
but i'm nowhere passing it as &T?
Denis
@mexus
Apr 04 2018 19:19
&self.foo.prop
Dylan DPC
@Dylan-DPC
Apr 04 2018 19:19
in the original code i have it as self.foo.prop
and still getting the same error
oh wait i see it
let me give it a try
Denis
@mexus
Apr 04 2018 19:19
i kinda don't believe you :)
changed &self to self and it works
Dylan DPC
@Dylan-DPC
Apr 04 2018 19:20
haha
i was calling it in 2 places, one as &self and the other as self
yeah it works. Thanks :)
Denis
@mexus
Apr 04 2018 19:22
np :+1: btw are you sure you want to put bounds on the structs themselves? https://play.rust-lang.org/?gist=a3722a92217abcade407cd1c61531273&version=stable
another btw -- you probably don't want to box a reference