#Does String::from("some string here"); clone the bytes of the supplied literal to a heap alloc?

3 messages · Page 1 of 1 (latest)

rancid plover
#

If &str is not growable but String is, the bytes in a String will need to be on the heap so when I do String::from does it clone the bytes right away or does it wait till I try to grow the container and then copy the bytes to the new one on the heap.

peak dragon
slim crystal
#

Yeah, whatever character data the &str is referencing could be dropped before the String grows, and then it can't copy over the bytes, so it does it right away.