I've been looking for a little information I can't seem to find on the web, which is: is cloning an &str free? Or does it clone the entire data like a String::clone would?
For context, I need to clone the following structure:
&str is a Copy type (more generally, &T is Copy for all T), which means that clone is just memcopy. the std::mem::size_of::<&str>() is 16 on 64 bit System (two pointers wide), so it copies only a relatively small bit of data.
So yeah, napkin calculation suggests that it should be more or less free.
Note that &str is not a string by itself; it's only a reference into already existing string. Cloning that string, of course, would be expensive (if this is real String and not something like Rc<str>, of course), but cloning a reference is cheap.