Skip to content
Justice Tech School

String and &str

&str is a borrowed view of text. String is an owned growable string.

Example
fn main() {
    let s: &str = "hello";
    let mut o = String::from(s);
    o.push_str(" world");
    o.push('!');
    println!("{} {} {}", s, o, o.len());
}

Result

hello hello world! 12

Exercise

Owned string.

let s = ::from("a");

Quiz Test

Which is growable?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.