Rust Tutorials

Rust is a modern systems programming language focusing on safety, speed, and concurrency. It is syntactically similar to C++, but is designed to provide better memory safety while maintaining high performance.

Rc<T>, the Reference Counted Smart Pointer
Rc<T>, the Reference Counted Smart Pointer
In this lab, we will be exploring the use of Rc<T> (reference counting) in Rust for enabling multiple owners of a value by tracking the number of references to the value and ensuring it is only cleaned up when there are no owners.
Rust
Online Rust Playground
Online Rust Playground
Discover the Online Rust Playground, a versatile platform that empowers developers to write, test, and share Rust code effortlessly.
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
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
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
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
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
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
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
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
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
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
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
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
Rust Module Visibility Exploration
Rust Module Visibility Exploration
In this lab, we learn about the visibility of items in Rust modules, including the default private visibility, the use of the pub modifier to override visibility, and the different levels of visibility such as pub(in path), pub(self), pub(super), and pub(crate). We also explore nested modules and the restrictions on accessing private items within modules.
Rust
Defining Generic Functions in Rust
Defining Generic Functions in Rust
In this lab, you will learn how to define generic functions in Rust. To make a function generic, you need to prepend the type T with <T>. Sometimes, you may need to explicitly specify type parameters while calling a generic function, which can be done using the syntax fun::<A, B, ...>(). The code provided demonstrates the usage of generic functions in Rust and includes examples of functions that are both generic and non-generic.
Rust
Exploring Rust's Functional Capabilities
Exploring Rust's Functional Capabilities
In this lab, we explore higher-order functions (HOFs) in Rust, which are functions that take one or more functions and/or produce a more useful function, and how they can be used in combination with lazy iterators to give Rust a functional flavor.
Rust
Diverging Functions in Rust
Diverging Functions in Rust
In this lab, we learn about diverging functions that are marked using ! in Rust. Diverging functions never return and their return type is an empty type. This is different from the () type which has only one possible value. Diverging functions can be useful when casting to any other type is required, such as in match branches. They are also the return type of functions that loop forever or terminate the process.
Rust
  • Prev
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • ...
  • 14
  • Next