Rust

Rust

Made by DeepSource

Found occurrence of Box::new("..") RS-W1058

Anti-pattern
Minor

Prefer Box::from("..") over Box::new("..").Box::new("..")simply stores a _pointer_ to those bytes, on the heap, whereas,Box::from("..")actually allocates bytes of thestr` on the heap.

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::from(<str>) or String::from(<str>).

Bad practice

fn foo() -> Box<&str> {
    Box::new("a str")
}

Recommended

fn foo() -> Box<str> {
    Box::from("a str")
}