Box::new("..")
RS-W1058Prefer Box::from("..")
over Box::new("..").
Box::new("..")simply stores a _pointer_ to those bytes, on the heap, whereas,
Box::from("..")actually allocates bytes of the
str` 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>)
.
fn foo() -> Box<&str> {
Box::new("a str")
}
fn foo() -> Box<str> {
Box::from("a str")
}