the.bay.news

Generic Implementation for both values and references to values of a certain trait

The Rust Programming Language Forum
Generic Implementation for both values and references to values of a certain trait
I wish to have an implementation for a struct with a generic that works when the generic is of a certain trait and ALSO when it is a reference to a value of the trait without duplicated code. Here is a short example of the functionality I wish to have: struct Foo<T>(T); impl<T> Foo<T> where T: Bar, { fn foo_bar(&self) { self.0.trait_method(); } } trait Bar { fn trait_method(&self) { println!("trait method called"); } } struct Baz; impl Bar for Baz {} fn ...

I wish to have an implementation for a struct with a generic that works when the generic is of a certain trait and ALSO when it is a reference to a value of the trait without…

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.