Impl <T> Bar<T> { ... additional properties ... }

Suppose we have:

impl<T> Bar<T> {
  ...
}

ijpl<T: OtherT> Bar<T> {
  ... more functions ...
}

is there a way to combine this into a single impl of the form

impl<T> Bar<T> {
  ... normal stuff ...

  {
    .. additional stuff when T also satisfies OtherT ...
  }

}

Each of the additional items can have more where T: ... constraints, but if you want to share that along many, you need a new impl block. Why do you want to avoid that?

You can put bounds on individual fns.

impl<T> Bar<T> {
    fn additional_stuff() where T: OtherT {
    }
}
1 Like

No strong reason.

Mainly testing out aesthetic preferences regarding how things look / are blocked in code-folded mode in IntelliJ.

Sometimes a struct can have a clutter of 5-10 different 'impl' blocks for a single struct.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.