Member-only story
Rust Adventures: Introduction to Collections — String
Hi there folks!
We are back with the last part of Collections, this time we are talking about Strings!
Yeah, you read it right. In Rust, Strings are part of collections family.
So let’s begin.
What are Strings?
Strings are a sequence of characters that can represents texts. They are encoded following a Unicode Standard Character Encoding. In some languages they can be designed as a Set of characters, in others just a value to hold by variable.
This data type is not a simple one and brings a lot of challenges. There is a good number of written languages and some of them have different characters. You can have, for example, the Latin based alphabet like English with 27 characters or the Chinese one with more than 6500.
Rust uses the UTF-8 encoding capable of storing 1,112,064 valid characters using one to four bytes. This makes it capable of handling any language and even some icons.
Rust and Strings
Rust has a single core data type to string str
that is a slice and is used normally as a reference &str.
This is a immutable data structure and has its security and limitation.