Closed
Description
Imagine the following scenario:
There is a trait A
that has many associated types. There are many functions in a program that take a Box<A>
only with specific associated types. To avoid having to write out all this boilerplate (including importing all the associated types), I want to create an alias for A
with these specific associated types. A type alias cannot work, because you can't do impl Foo for Bar
where Foo
is a type alias. Let's try subtraits:
trait A {
type Assoc;
// Pretend there are several more associated types here to make uses of `Box<A>` inconvenient.
}
trait B: A<Assoc=()> {}
fn takes_b(b: Box<B>) {}
This results in:
error[E0191]: the value of the associated type `Assoc` (from the trait `A`) must be specified
--> src/lib.rs:8:19
|
8 | fn takes_b(b: Box<B>) {}
| ^ missing associated type `Assoc` value
This seems like it should work. Note that declaring B
this way is valid, as the program compiles if takes_b
is commented out.
Metadata
Metadata
Assignees
Labels
No labels