In this example, the function foo
only accepts a
as argument. If changed to accept &dyn Trait
, it would only accept b
as argument and not a
.
trait Trait {}
fn foo<T: Trait>(_: T) {}
fn demo(a: impl Trait, b: &dyn Trait) {
foo(a);
foo(b);
}
error[E0277]: the trait bound `&dyn Trait: Trait` is not satisfied
--> src/lib.rs:7:9
|
3 | fn foo<T: Trait>(_: T) {}
| ----- required by this bound in `foo`
...
7 | foo(b);
| ^ the trait `Trait` is not implemented for `&dyn Trait`
Is there a way such that a function would be able to accept both a
and b
as an argument?