I have a function which returns a struct with PhantomData, where I discard the result. An example of this looks like:
use std::marker::PhantomData;
struct Foo<T> {
marker: PhantomData<T>,
}
fn foo<T>() -> Foo<T> {
// something useful
Foo {
marker: PhantomData,
}
}
fn main() {
let _ = foo();
}
This code produces this error:
error[E0282]: type annotations needed for `Foo<T>`
--> src/main.rs:15:9
|
15 | let _ = foo();
| ^
|
help: consider giving this pattern a type, where the type for type parameter `T` is specified
|
15 | let _: Foo<T> = foo();
| ++++++++
What is the best type to assign here? (does it not matter?)
>Solution :
Usually for unused type parameters one would use () also known as unit.