Trying to use T as generic parameter of a trait of another generic parameter this way:
pub trait Foo<T> {
fn foo() -> T;
}
struct Bar<T, F: Foo<T>> {
f: F,
}
fn main() {
}
Failing with:
error[E0392]: parameter `T` is never used
--> src/main.rs:5:12
|
5 | struct Bar<T, F: Foo<T>> {
| ^ unused parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
The compiler advice is to use PhantomData
:
use core::marker::PhantomData;
pub trait Foo<T> {
fn foo() -> T;
}
struct Bar<T, F: Foo<T>> {
f: F,
t: PhantomData<T>,
}
fn main() {
}
Isn't there a more elegant way to deal with this than creating a fake field with a strangely named traits?