
Rust Panic Handling and Memory Safety
In this lab, we learn about the panic! macro in Rust, which can be used to generate a panic and start unwinding its stack, causing the program to report the panic message and exit. The runtime takes care of freeing all the resources owned by the thread by calling the destructor of its objects. We also look at an example of using the panic! macro to handle division by zero and verify that it doesn't result in memory leaks using Valgrind.
Rust

Box, Stack and Heap
In this lab, the concept of boxing, stack allocation, and heap allocation in Rust is explored. All values in Rust are stack allocated by default, but they can be boxed (allocated on the heap) using the Box<T> type. A box is a smart pointer to a heap-allocated value, and when it goes out of scope, its destructor is called and the memory on the heap is freed. Boxing allows for the creation of double indirection and can be dereferenced using the * operator. The lab provides code examples and explanations of how boxing works and how it affects memory allocation on the stack.
Rust

Online Rust Playground
LabEx offers an Online Rust Playground, a cloud-based environment that allows you to quickly set up a Rust development environment for learning and experimentation.
Rust

Rust Operator Simplifies Error Handling
In this lab, the ? operator is introduced as a way to make code cleaner when chaining results. It is used at the end of an expression returning a Result and simplifies the code by automatically handling the Err and Ok branches. The example provided demonstrates how to use the ? operator in Rust to handle various math operations and their potential errors.
Rust

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

The Use Declaration
In this lab, we will explore the use declaration in Rust, which allows us to bind a full path to a new name for easier access, and can be used with the as keyword to bind imports to a different name. Example code snippets demonstrate how to use the use declaration to simplify accessing functions and modules within nested paths.
Rust

Super and Self
In this lab, we explore the usage of the super and self keywords in Rust for removing ambiguity and avoiding hardcoded paths when accessing items.
Rust

Conditional Compilation with Rust's cfg Attribute
In this lab, you will learn about the cfg attribute and cfg! macro in Rust, which allow for conditional checks in configuration and evaluation, respectively. The cfg attribute enables conditional compilation, while the cfg! macro evaluates to true or false at run-time. Code blocks using cfg! must be valid regardless of the evaluation result, unlike #[cfg] which can remove code.
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

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

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

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

Conditional Rust Function Compilation
In this lab, we have a code snippet that includes a function called conditional_function(), but it will only be compiled and executed if a custom conditional called some_condition is passed to rustc using the --cfg flag.
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

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

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

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

Cargo Attributes in Rust Development
In this lab, it is explained that the crate_type and crate_name attributes in Rust have no effect when using Cargo, the Rust package manager, which is widely used for Rust projects.
Rust