It's important to know that a String has two parts:
- The struct itself, which contains a pointer and two integers (length and capacity).
- The allocation on the heap, pointed at by the pointer.
Moving a String only moves the first part. The allocation is not moved, and this makes it cheap to move a String.
Of course, in your example, it is better to not move it, but sometimes the function actually needs ownership of the value, and in that case, you must move it.