The phrase
Unicode string character by character can consume a lot more memory
than you expected. The string love: ❤ is 7 characters long, requires 12
bytes of storage in a String—and 32 bytes of memory when processed as
individual characters. This may seem like a small amount of memory,
but if your reader enters the entirety of War and Peace into your program’s
input box, per-character parsing may require more resources than you
expected
gives, in my humble opinion, the wrong idea that iterators allocate memory.
What’s written is true if I do my_string.chars().collect::<Vec<char>>()
, but only iterating overs chars won’t consume any memory, the single chars are transmuted from original string bytes.
I suggest to reformulate the example clarifing that iterators won’t allocate memory