RS.CLIPPY.OPTION_MAP_UNIT_FN
Using `option.map(f)`, where `f` is a function or closure that returns `()`
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: option_map_unit_fn. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of option.map(f) where f is a function
or closure that returns the unit type ().
Why is this bad?
Readability, this can be written more clearly with an if let statement
Example
let x: Option<String> = do_stuff();
x.map(log_err_msg);
x.map(|msg| log_err_msg(format_msg(msg)));
The correct use would be:
let x: Option<String> = do_stuff();
if let Some(msg) = x {
log_err_msg(msg);
}
if let Some(msg) = x {
log_err_msg(format_msg(msg));
}