Skip to content

Another kind of manual map #11519

@ronnodas

Description

@ronnodas

What it does

Replace Some(f(...?)) or Ok(f(...)?) as a return value with (...).map(f). Potentially an addition to manual_map.

Advantage

Clearer, has less nesting, and can be more concise. Helps discoverability of Option::map etc.

Drawbacks

Can be less concise.

Example

fn maybe_len(maybe_string: Option<&str>) -> Option<usize> {
    Some(maybe_string?.len())
}

Could be written as:

fn maybe_len(maybe_string: Option<&str>) -> Option<usize> {
    maybe_some_string.map(|s| s.len())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions