Rust

Rust

By DeepSource

Found occurrence of `Rc::new("..")`RS-W1062

Anti-pattern

Prefer Rc::from("..") over Rc::new(".."). -Rc::new("..")simply stores a _pointer_ to bytes (&str), on the heap -Rc::from("..")actually allocates bytes of thestr` on the heap

Rc<&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 Rc::from(<str>).

Examples

Bad practice

fn get_rc_str() -> Rc<&'static str> {
    Rc::new("a str")
}

Recommended

fn get_rc_str() -> Rc<str> {
    Rc::from("a str") // Is better
}