Closed
Description
What it does
The lint suggests replacing e.g. u16::from_str_radix(&string, 10)
with string.parse()
.
(Obviously, it could also be any other primitive with such associated function).
Categories (optional)
- Kind: perhaps this could go in
clippy::style
.
What is the advantage of the recommended code over the original code?
The resulting code is shorter, easier to read and doesn't involve using 10
as a magic number.
Drawbacks
Using str::parse
instead, the user might have to specify types in some cases.
Example
let input: &str = get_input();
let num = u16::from_str_radix(input, 10)?;
Could be written as:
let input: &str = get_input();
let num: u16 = input.parse()?;
(In a more complicated use case, the type of num
will probably be inferred.)