Daily Learnings: Tue, Apr 16, 2024
Let us be grateful to people who make us happy; they are the charming gardeners who make our souls blossom. — Marcel Proust
More Notes on Rust Strings
I spent some time today continuing my VERY slow study about Rust.
- Misc tip:
.into()is a method for casting in Rust Stringtype is defined in the Rust standard library (std), and is stored as a vector of bytes (Vec)- It’s guaranteed to always be a valid UTF-8 sequence
- It’s growable and NOT
null-terminated
- Use the
String.push_str()method when mutating / pushing more characters onto an existingString- Note: Use the
String.push()method when pushing a singlecharinto an existingString - You can also use the
+=syntax to push characters onto an existingString
- Note: Use the
fn main() {
let mut S: String = String::from("hello");
s.push(',');
s.push_str(" world");
s += "!";
}