Member-only story
Difference between len() vs chars().count() in Rust
If you are coming from different languages like Python, you might guess that len() return the length of variable, if it is String, means the number of characters in it, but indeed it is not.
Instead String.len() return the bytes of that String.
If you want to get the number of characters in String, you need String.chars().count().
Take this snippet code for demonstration:
Running this code will show
The length of "ラウトは難しいです!" is 30.
The number of chars of "ラウトは難しいです!" is 10.
Hope it helps~~
~~PEACE~~