How to ensure trait bounds within a trait?

Viewed 47

If I have a trait like the following Foo trait

trait Foo: Bar {
  type Account: SomeTrait;
}

That has a trait bound that requires Bar

trait Bar {
  type UserId;
}

How can I request inside the Foo trait that this trait requires the UserId type inside the Bar trait to be u32?

Important note: I can't edit the Bar trait.

1 Answers

This can be specified as a named generic argument: Bar<UserId=u32>.

trait SomeTrait {}

trait Foo: Bar<UserId=u32> {
    type Account: SomeTrait;
}

trait Bar {
    type UserId;
}

See the playground.

Related