5/5
# Array ## Example Execute the following command to run [`./solutions/examples/array.rs`](./solutions/examples/array.rs) ```shell cargo run --example array ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](./exercises/src/lib.rs) ### Exercise 1 ```rust pub fn zeros() -> [u32; 100] { todo!(); } ``` Return an array with 100 elements, all equal to 0. ### Exercise 2 ```rust pub fn first_3(s: &[u32]) -> &[u32] { todo!(); } ``` Return a slice of the first 3 elements of `s`. ### Exercise 3 ```rust pub fn last_3(s: &[u32]) -> &[u32] { todo!(); } ``` Return a slice of the last 3 elements of `s`. ## Test ```shell cargo test ```
Execute the following command to run ./solutions/examples/array.rs
Exercises are in ./exercises/src/lib.rs
Return an array with 100 elements, all equal to 0.
Return a slice of the first 3 elements of s
.
Return a slice of the last 3 elements of s
.
An elemental guide to Array - Delve into Rust's fixed-size arrays, understanding their creation and how to access specific portions. Practice initializing an array with zeros and master techniques for slicing out the first or last few elements.
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