3 ms·
In Rust, passing a string by value is a move, and it won't copy the backing buffer at most it copies the stack structure (24 bytes) and possibly not even that (
by masklinn 10y ago
In Rust, passing a string by value is a move, and it won't copy the backing buffer at most it copies the stack structure (24 bytes) and possibly not even that (depending on the way it's used).
As to why, well because the function asks for it, either because it generically works on values, or because it consumes the string to avoid copying its internal buffer (e.g. https://doc.rust-lang.org/std/string/struct.String.html#method.into_bytes https://doc.rust-lang.org/std/string/struct.String.html#meth...), or whatever other reason. Either way that's a completely valid use.