Hello. What is wrong with this code?
pub struct VectorFormer<ContainerEnd>
where
ContainerEnd: Fn(),
{
on_end: ContainerEnd,
}
impl<ContainerEnd> VectorFormer<ContainerEnd>
where
ContainerEnd: Fn(),
{
fn new(on_end: ContainerEnd) -> Self {
Self { on_end }
}
}
//
pub struct CommandFormer {}
impl CommandFormer {
pub fn problem<ContainerEnd>() -> VectorFormer<ContainerEnd>
where
ContainerEnd: Fn(),
{
let on_end = || {
println!("on_end");
};
VectorFormer::<ContainerEnd>::new(on_end)
}
}
Output:
|
37 | pub fn problem<ContainerEnd>() -> VectorFormer<ContainerEnd>
| ------------ this type parameter
...
41 | let on_end = || {
| ______________________-
42 | | println!("on_end");
43 | | };
| |_________- the found closure
44 | VectorFormer::<ContainerEnd>::new(on_end)
| ^^^^^^ expected type parameter `ContainerEnd`, found closure
|
= note: expected type parameter `ContainerEnd`
found closure `[closure@src/main.rs:41:22: 43:10]`
= help: every closure has a distinct type and so could not always match the caller-chosen type of parameter `ContainerEnd`