RS.CLIPPY.RESULT_MAP_UNIT_FN
Using `result.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: result_map_unit_fn. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of result.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: Result<String, String> = do_stuff();
x.map(log_err_msg);
x.map(|msg| log_err_msg(format_msg(msg)));
The correct use would be:
let x: Result<String, String> = do_stuff();
if let Ok(msg) = x {
log_err_msg(msg);
};
if let Ok(msg) = x {
log_err_msg(format_msg(msg));
};