5/5
# `String` and `&str` ## Example Execute the following command to run [`./solutions/examples/string.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/string/solutions/examples/string.rs) ```shell cargo run --example string ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/string/exercises/src/lib.rs) ### Exercise 1 ```rust pub fn hello() -> String { todo!(); } ``` Create a function that returns the `String` `"Hello Rust"`. ### Exercise 2 ```rust pub fn greet(name: &str) -> String { todo!(); } ``` Create a function returns `"Hello "` appended with `name`. ### Exercise 3 ```rust pub fn append(mut s: String) -> String { todo!(); } ``` Create a function that appends `"!"` to `s`. ## Test ```shell cargo test ```
String
and &str
Execute the following command to run ./solutions/examples/string.rs
Exercises are in ./exercises/src/lib.rs
Create a function that returns the String
"Hello Rust"
.
Create a function returns "Hello "
appended with name
.
Create a function that appends "!"
to s
.
An essential primer on `String` and `&str` - Explore Rust's core text types, understanding the distinction between owned `String`s and borrowed `&str` slices. You'll practice these concepts by creating, concatenating, and appending strings in hands-on exercises.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on July 11, 2025
Rust Developer
Rust Programming BasicsDuration: 6min
Duration: 18min
Duration: 47min
Duration: 15min
Duration: 19min
Duration: 8min
Duration: 12min
Duration: 46min
Duration: 14min
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on July 11, 2025