January 2019
Beginner to intermediate
554 pages
13h 31m
English
The String type comes from the standard library and is a heap-allocated UTF-8 encoded sequence of bytes. They are simply Vec<u8> under the hood but have extra methods that are applicable to only strings. They are owned types, which means that a variable that holds a String value is its owner. You will usually find that String types can be created in multiple ways, as shown in the following code:
// strings.rsfn main() { let a: String = "Hello".to_string(); let b = String::from("Hello"); let c = "World".to_owned(); let d = c.clone();}
In the preceding code, we created four strings in four different ways. All of them create the same string type and have the same performance characteristics. The first variable, a, creates ...
Read now
Unlock full access