Rust Tutorials

Rust provides a structured approach to learning systems programming and memory safety. Our tutorials cover Rust syntax, ownership concepts, and concurrent programming, suitable for beginners and experienced programmers. Through hands-on labs and practical examples, you'll gain proficiency in writing safe and efficient Rust code. Our Rust playground allows you to experiment with Rust features in real-time.

Rust Raw Identifiers Introduction
Rust Raw Identifiers Introduction
In this lab, we will learn about raw identifiers in Rust, which allow us to use keywords as identifiers in situations where they are typically not allowed, such as variable or function names, especially when older editions of Rust clash with newer keywords.
Rust
Your First Rust Lab
Your First Rust Lab
Hi there, welcome to LabEx! In this first lab, you'll learn the classic 'Hello, World!' program in Rust.
Rust
Rust Formatting and Display Trait
Rust Formatting and Display Trait
In this lab, we learned about formatting in Rust and how to use the format! macro to format variables. We saw that formatting is specified using a format string, and different argument types can be used to format the same variable in different ways. The most common formatting trait is Display, which handles cases where the argument type is left unspecified. We saw an example of implementing the Display trait for a City struct, where we formatted the latitude and longitude values. We also saw an example of a Color struct and were tasked with implementing the Display trait for it to display the RGB values and their hexadecimal representation.
Rust
Exploring Rust Tuples and Transposing Matrices
Exploring Rust Tuples and Transposing Matrices
In this lab, we explore tuples in Rust. Tuples are collections of values of different types and are constructed using parentheses. They can be used as function arguments and return values, allowing functions to return multiple values. Tuples can also be used as members of other tuples. Rust provides tuple indexing to access values in a tuple. Tuples are printable and can be destructured to create bindings. Additionally, we learn how to add the fmt::Display trait to a struct to customize its printing format. Finally, we are given an activity to implement a transpose function that swaps two elements in a matrix.
Rust
Exploring Rust's Associated Types
Exploring Rust's Associated Types
In this lab, we explore the concept of associated types in Rust, which allows for improved readability of code by defining inner types locally within a trait as output types. This is achieved by using the type keyword within the trait definition. with associated types, functions that use the trait no longer need to explicitly express the types A and B, making the code more concise and flexible. We rewrite an example from a previous section using associated types to illustrate their usage in practice.
Rust
New Type Idiom
New Type Idiom
In this lab, we explore the newtype idiom, which provides compile-time guarantees by allowing us to create a new type that is distinct from its underlying type. An example is shown where a struct Years is used to represent age in years, and a struct Days is used to represent age in days. By using the newtype idiom, we can ensure that the right type of value is supplied to a program, such as in the age verification function old_enough, which requires a value of type Years. Additionally, we learn how to obtain the value of a newtype as its underlying type using tuple or destructuring syntax.
Rust
Rust Generics Type Constraints
Rust Generics Type Constraints
In this lab, when working with generics in Rust, type parameters must be bounded by traits to specify the functionality a type must implement.
Rust
Implementing Generic Types in Rust
Implementing Generic Types in Rust
In this lab, we learn how to implement generic types and methods in Rust, allowing us to specify different type parameters when using the struct or calling the methods.
Rust
Expressive Rust Generics with Where Clause
Expressive Rust Generics with Where Clause
In this lab, we learn that a where clause in Rust can be used to express bounds for generic types separately from their declaration, allowing for clearer syntax, and can also apply bounds to arbitrary types rather than just type parameters. The where clause is especially useful when the bounds are more expressive than the normal syntax, as shown in the example involving the PrintInOption trait.
Rust
Testcase: Empty Bounds
Testcase: Empty Bounds
In this lab, the code showcases how traits can be used as bounds, even if the traits do not include any functionality, by using the Eq and Copy traits as examples.
Rust
Implement Generic Double Deallocation Trait
Implement Generic Double Deallocation Trait
In this lab, a generic DoubleDrop trait is defined, which includes a double_drop method that allows a type to deallocate itself and an input parameter.
Rust
Phantom Type Parameters
Phantom Type Parameters
In this lab, we explore the concept of phantom type parameters, which are type parameters that are checked statically at compile time and do not have any runtime behavior or values. We demonstrate their usage in Rust by combining std::marker::PhantomData with the concept of phantom type parameters to create tuples and structs that contain different data types.
Rust
Testcase: Unit Clarification
Testcase: Unit Clarification
In this lab, the implementation of the Add trait with a phantom type parameter is examined using the example code provided in Rust.
Rust
Rust Multiple Bounds Exploration
Rust Multiple Bounds Exploration
In this lab, the code demonstrates the concept of multiple bounds in Rust, where a single type can have multiple bounds applied using the + operator.
Rust
Generic Container Trait Implementation
Generic Container Trait Implementation
In this lab, we have a trait called Contains that is generic over its container type and requires explicit specification of its generic types when implemented for the Container type.
Rust
Creating a Library
Creating a Library
In this lab, we will create a library called rary in Rust. The rary library contains a public function called public_function, a private function called private_function, and an indirect access function called indirect_access. Afterwards, we compile the library using the rustc command, resulting in a file named library.rlib.
Rust
Rust Software Testing Fundamentals
Rust Software Testing Fundamentals
In this lab, we will explore the importance of testing in software development using Rust and how to write different types of tests such as unit tests and integration tests. We will also learn about organizing tests in Rust projects and running them using the cargo test command. Additionally, we will discuss the potential issues that can arise from running tests concurrently and provide an example to illustrate this.
Rust
Using a Library
Using a Library
In this lab, to link a crate to a new library in Rust, you can use the rustc command's --extern flag and import all of its items under a module with the same name as the library.
Rust
  • Prev
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • ...
  • 14
  • Next