but when calling new with None, Rust cannot infer the type for T:
let y = Foo::new(None);
19 | let y = Foo::new(None);
| - ^^^^^^^^ cannot infer type for type parameter `T`
| |
| consider giving `y` the explicit type `Foo<T>`, where the type parameter `T` is specified
but what type should I specify for this None input? Here is my playground test.
If you don't care what type you get, just pick any type. The unit type () is a reasonable default choice that shows you aren't using the type for anything:
let y: Foo<()> = Foo::new(None);
On the other hand, if you want to later do something with y that requires a specific type, then you can pick that type explicitly, or let it be inferred based on that later usage.
It seems to me that the trait bounds in my code is too complex for adopting the suggested approaches, I ended up with a different design that don't need the Option<T> . Somehow I guess the complexity of generics / trait bounds forced me to find a simpler (and better I hope) design
Btw, the trait bounds for Option<F> in my code was something like:
where
F: Fn(Request<Body>) -> S + Send + Clone + 'static,
S: Future<Output = Response<Body>>,