Skip to content

Passing members as closures. #13813

Closed
Closed
@ddrcoder

Description

@ddrcoder

I can't seem to figure out how to pass member functions as closures. I can do this:

fn my_unwrap<T>(o: Option<T>) -> T { o.unwrap() }

// name non-member function
let vals = opts.map(my_unwrap);
// take value, call member
let vals = opts.map(|o| o.unwrap());
// pass member function...?
let vals = opts.map(Option::unwrap); // doesn't compile

But I see no way to pass the actual member function within std::Option. Perhaps I missed something in the documentation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions