.filter(..).next() is equivalent to
.clone()in assignment RS-W1070
.clone_from() instead of assigning the result of
clone_from() may perform better in some cases because some structs may have custom implementations of
clone_from(), which improve performance by avoiding needless allocations.
std::mem module provides the
take() method to acquire the
current value and replace it with the default value of the same type.
Prefer using this over
.clamp(min, max), instead of
Ord::max functions can be replaced with
Ord::clamp, which is also a more readable solution.
Checking if a value is
None via a direct comparison is usually inspired
from other programming languages (e.g.
foo is None in Python). In Rust,
Eq trait is used to perform the comparison, which is unneeded.
Option type provides the
is_some() methods which
return a boolean, allowing for more idoimatic comparison.
A function with high cyclomatic complexity can be hard to understand and maintain. Cyclomatic complexity is a software metric that measures the number of independent paths through a function. A higher cyclomatic complexity indicates that the function has more decision points and is more complex.
Option provides the
take() method for acquiring its current
None) and replacing it with
using this over
0 as *const is the same as
which is more idiomatic and readable. Similarly
0 as *mut is same as
then_some(..).unwrap_or(..) obfuscates the comparison itself
and reduces code readability. It can be better written as an if-else
When using static
Mutex in Rust, it was common practice to wrap them inside a
OnceCell for safe initialization. Since Rust 1.63, this is no longer necessary as global static
Mutex's can be initialized without any wrapper. Therefore, using a
OnceCell with a
Mutex is redundant and adds unnecessary complexity to the code.
If your code uses a
OnceCell to wrap a global static
Mutex, you can simplify it by removing the
OnceCell wrapper and initializing the
Lint attributes have no effect on crate imports. Neither can lint-attributes affect module-space attributes of the imported items.
Expressions of the form
x == true,
!y == false are unnecessary. Consider using the variable directly.
SeekFrom::Start(0) as the position is equivalent to
Seek::rewind. Consider using
Seek::rewind to improve readibility.
Rc::new("..").Rc<&str>` is a pointer to a
pointer. This adds another level of indirection without any benefit whatsoever.
Casting values from a larger type to a smaller type is error-prone. This can be
avoided when casting
char literals to
u8 by using the byte literal
Empty tuple fields in structs or enum variants do not affect the program in a meaningful way other than making the variant or struct identifier a constructor type rather than a value type. Consider revisiting this definition.
All integer types provide the size of the type in bits through
Consider using this instead of manually calling
and multiplying the result by 8.
Vec type provides the
first_mut() methods to retrieve
the first element of the vector. Similarly, the
VecDeque type provides the
Prefer using these instead of
print!in implementation of
fmt method provided by the
Debug trait uses a formatter to
generate the output string. It does not directly write to stdout or
eprint! in this implementation leads to
incorrect functionality. Instead, use the standard suite of debug
representations provided by the Formatter trait (
debug_map). If you wish
to use a custom representation for debugging, you can use the