The Type of Owned Strings
We'll cover the following...
The type of an owned string is String
. You can test this by modifying the program above to have a type annotation, e.g.,
Press + to interact
fn main() {let first_name = "Michael".to_owned();let last_name = " Snoyman";let full_name: String = first_name + last_name;println!("Full name is {}", full_name);}
However, when you get a type error, the compiler will usually give you a slightly more verbose name. If I make a mistake and say i32
instead of String
, I’ll get this error message: