Rust

Rust

By DeepSource

Usage of expect followed by a function call RS-W1030
Performance

Calls to expect followed by a function call should be replaced with unwrap_or_else to increase laziness. The argument to expect is evaluated eagerly and unconditionally. The argument to unwrap_or_else is evaluated lazily and only if required, sometimes leading to lower overhead and fewer allocations.

Needless iteration over collection that allows indexing RS-W1091
Performance

Using .iter().nth(_) is a method of accessing the nth element of an iterable. However, some collections such as slices or VecDeques allow direct access to the nth element through helper methods such as get and get_mut (for mutable access). Not only are these methods more consise, they are also more performant.

Unnecessary collect() on iterable to Vec RS-P1006
Performance
Autofix

Collecting Iterator to Vec has the possible cost of forcing allocation, hence instead directly using the iterator is more efficient quite often, if the Vec is unnecessary.

Found collapsible .replace(..) method calls RS-P1007
Performance

Multiple consecutive replace(..) calls with the same replacement text can result in poor performance. Oftentimes, these replace calls can be merged.

Usage of unwrap_or followed by a function call RS-W1031
Performance

Calls to unwrap_or followed by a function call should be replaced with unwrap_or_else or unwrap_or_default, to increase laziness. The argument to unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or unwrap_or_default are evaluated lazily and only if required, sometimes leading to lower overhead and fewer allocations.