Here i'm using a closure , where the compile is infering a impl trait rather than a type. According to rust book, a closure is a anonymous function. And we can only apply trait to type. On what basis compiler is infering like this?
`
fn main(){
let x = "sam".to_string();
let y: impl FnOnce() -> String = || x;
}
`
Here i'm using a closure , where the compile is infering a impl trait rather than a type. According to rust book, a closure is a anonymous function. And we can only apply trait to type. On what basis compiler is infering like this?
`
fn main(){
let x = "sam".to_string();
let y: impl FnOnce() -> String = || x;
}
`