Prefer Rc::from("..")
over Rc::new("..").
-
Rc::new("..")simply stores a _pointer_ to bytes (
&str), on the heap
-
Rc::from("..")actually allocates bytes of the
str` 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>)
.
fn get_rc_str() -> Rc<&'static str> {
Rc::new("a str")
}
fn get_rc_str() -> Rc<str> {
Rc::from("a str") // Is better
}