Using copy with strings
The Go copy
built-in copies things from a source slice to a destination slice.
func copy(dst, src []Type) int
It is not using generics, but Type
here serves the same purpose. Or does it?
Not exactly! string
is a little-known exception:
As a special case, [copy] also will copy bytes from a string to a slice of bytes.
Next time you need to work with strings while reusing a work buffer, copy
might just be the perfect candidate to avoid ugly for rune loops.