Rc::new("..")
RS-W1062Prefer Rc::from("..")
over Rc::new("..").
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>)
.
In summary:
Rc::new("..")
simply stores a pointer to bytes (&str
), on the heapRc::from("..")
actually allocates bytes of the str
on the heapfn get_rc_str() -> Rc<&'static str> {
Rc::new("a str")
}
fn get_rc_str() -> Rc<str> {
Rc::from("a str") // Is better
}