Rust

Rust

By DeepSource

Found occurrence of Box<&str> RS-W1059

Anti-pattern

Box<&str> is redundant, use Box<str> instead.

Box<&str> is a pointer to a pointer. This adds another level of indirection without any benefit whatsoever. If the intention is to place a str on the heap, consider using Box<str> or String.

Examples

Bad practice

fn get_box_str() -> Box<&'static str> {
    Box::from("string")
}

Recommended

fn get_box_str() -> Box<str> {
    Box::from("string")
}