Rust Crab

Rust Documentation: Chapter 5

In the previous chapter, we saw we can use slices as references to a contiguous sequence of elements in a collection instead of the whole collection. In this chapter, we will deviate from Ownership rules and see how we can use structs to create custom data types. Structs In Rust, and in object-oriented programming languages, a Struct or structure is a custom data type that lets you hold multiple values in relation to it....

May 3, 2023 · 8 min · Tanmay
Rust Crab

Rust Documentation: Chapter 4 - Slices

In the previous chapter, we saw how references work in Rust when we do not directly want to transfer ownership. In this chapter, we will see how we can use slices to reference a contiguous sequence of elements in a collection instead of the whole collection. Slices Slices let you reference a contiguous sequence of elements in a collection rather than the whole collection. A slice is a kind of reference, so it does not have ownership....

May 3, 2023 · 5 min · Tanmay
Rust Crab

Rust Documentation: Chapter 4 - References

In the previous chapter, we saw how ownership works in Rust. The main drawback we saw was that for functions, the return value changes ownership and the original variable is no longer usable. In this chapter, we will look at a continuation of ownership, i.e. references. References Instead of passing variables to functions, we can pass references to functions. reference is like a pointer we can follow to get to the data....

May 1, 2023 · 8 min · Tanmay
Rust Crab

Rust Documentation: Chapter 4 - Ownership

In the previous chapter, we saw how we can use data types, functions, and control flow in rust. In this chapter, we will look at the most unique feature of rust - ownership. Ownership Ownership enables Rust to make memory safety guarantees without needing a garbage collector, so it’s important to understand how ownership works. In this chapter, we’ll talk about ownership as well as several related features: borrowing, slices, and how Rust lays data out in memory....

April 29, 2023 · 8 min · Tanmay
Rust Crab

Rust Documentation: Chapter 3

In the previous chapter, we built a simple guessing game. Now, we will learn more about variables, data types, mutability, and control flow in Rust Variables and Mutability In Rust, we define variables with let keyword. However, variables by default are not mutable in Rust. This means that once a variable is defined, it cannot be changed. To make a variable mutable, we use the mut keyword after the let keyword....

April 26, 2023 · 9 min · Tanmay