Stream: general

Topic: generic trait for generic struct

Daniel Papp (May 31 2019 at 13:26, on Zulip):

Suppose I have the following struct

struct Point<T> {
  x: T,
  y: T,

And also I have a generic trait defined in the following way:

trait SomeTrait<U> {
  fn do_stuff(self, x: U) {}
Daniel Papp (May 31 2019 at 13:27, on Zulip):

And I want to implement the generic trait for the generic struct. How do I do that?

oli (May 31 2019 at 13:31, on Zulip):

impl<V> SomeTrait<V> for Point<V> {} (can also just use T instead of V)

Last update: Aug 13 2020 at 09:15UTC