Rust

Rust

Made by DeepSource

Found manual implementation of eq() on OsString RS-W1134

Anti-pattern
Minor

The eq() method on the OsString type can be used to compare against &str, and &OsStr too. Consider using this instead of manually implementing the comparison with to_str().map(.. == ).

Bad practice

use std::ffi::OsString;

fn foo() {
    let s1: OsString = OsString::from("Hello there");
    if s1.to_str().map(|s| s == "Hello there").unwrap_or_default() {
        println!("Matches!");
    }
}

Recommended

use std::ffi::OsString;

fn foo() {
    let s1: OsString = OsString::from("Hello there");
    if s1.eq("Hello there") {
        println!("Matches!");
    }
}