Skip to content

Closure return types #17

Description

@Linux-Server

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;
}

`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions