January 2019
Beginner to intermediate
554 pages
13h 31m
English
Strings are one of the most frequently used data types in any programming language. In Rust, they are usually found in two forms: the &str type (pronounced stir) and the String type. Rust strings are guaranteed to be valid UTF-8 encoded byte sequences. They are not null terminated as in C strings and can contain null bytes in-between them. The following program shows the two types in action:
// strings.rsfn main() { let question = "How are you ?"; // a &str type let person: String = "Bob".to_string(); let namaste = String::from("नमस्ते"); // unicodes yay! println!("{}! {} {}", namaste, question, person);}
In the preceding code, person and namaste are of type String, while question is of type &str. There are multiple ways you can create ...
Read now
Unlock full access