5/5
# Scalar types ## Example Execute the following command to run [`./solutions/examples/scalar.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/scalar/solutions/examples/scalar.rs) ```shell cargo run --example scalar --release ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/scalar/exercises/src/lib.rs) ### Exercise 1 ```rust pub fn eq() { todo!(); } ``` Fix the function `eq` inside [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/scalar/exercises/src/lib.rs) Compare 2 inputs of the type `char` for equality and return a `bool` ### Exercise 2 ```rust pub fn add() { todo!(); } ``` Fix the function `add` inside [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/scalar/exercises/src/lib.rs) Add 3 inputs of the type `f32` and return the sum ### Exercise 3 ```rust pub fn cast(x: u8, y: i8, z: f32) -> f32 { x + y + z } ``` Fix the function `cast` inside [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/scalar/exercises/src/lib.rs) Add the 3 inputs, casting all of them into `f32` ## Test ```shell cargo test ```
Execute the following command to run ./solutions/examples/scalar.rs
Exercises are in ./exercises/src/lib.rs
Fix the function eq
inside ./exercises/src/lib.rs
Compare 2 inputs of the type char
for equality and return a bool
Fix the function add
inside ./exercises/src/lib.rs
Add 3 inputs of the type f32
and return the sum
Fix the function cast
inside ./exercises/src/lib.rs
Add the 3 inputs, casting all of them into f32
An essential look at Scalar types - Discover Rust's core data components: integers, floats, booleans, and characters, the foundational units of information. Apply your knowledge through hands-on exercises in comparing `char`s, summing `f32` values, and performing numeric type casting.
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