Rust

Rust

Made by DeepSource

Invoking .map_or() with identity closure RS-W1201

Anti-pattern
Minor
Autofix

Calling map_or with the identity closure is equivalent to using unwrap_or which is both easier to read and generally more performant. Consider replacing map_or with unwrap_or.

Bad practice

let foo = vec![1, 2, 3];
let bar = foo.get(1).map_or(0, |x| x);

Recommended

let foo = vec![1, 2, 3];
let bar = foo.get(1).unwrap_or(0);