Box Smart Pointer in Rust

A pointer in programming is often a piece of data that directs to the location of another piece of data in memory. For example, your home address points to where you live. Smart pointers are data structures that act like pointers but also have additional metadata and capabilities to manage memory automatically and safely. Box smart pointers are one of the many smart pointers in Rust, it allows you to…

Understanding Dereferencing in Rust

Dereferencing is how we access the value that a reference points to. References are like signposts that guide us to the actual data. Imagine them as arrows pointing to a treasure! 💎 Technically, a pointer stores the address of another variable in memory. So, if we do something like the example below: my_ref will hold the address of x in memory. In that case, x is not equal to my_ref, make…

Raw String in Rust

Raw strings are handy when you’re working with content that has characters that would normally require escaping in a regular string. For instance, if you’re dealing with HTML, raw strings can save you from the headache of messing up the original HTML structure. Raw strings starts with r# and closes with a # like so: r#””#. Here is an example of a Javascript code being passed as a string using…

Choosing Between str and String in Rust

In this guide, we’ll explore the reasons for having two types of strings in Rust &str and String , how they work, how they are stored in memory, and when to use each of them. Grab your pop corn and let’s ride along! Why do we have two types of string in Rust? It’s normal for new Rust developers to ask this question: “Why do we have two types of…

Rust Lifetimes Simplified

This guide is an attempt to simplify Rust Lifetimes, it’s a series and will be divided into several chapters. We’ll start with chapter one today. Chapter 1 Lifetimes and its benefits In Rust programming, lifetimes is a critical yet misunderstood concept. Assuming we are not talking about programming, when we talk about lifetimes what comes to mind? According to Oxford Dictionary, a lifetime is the duration of a person’s life…

Understanding Rust’s memory magic with an analogy

Imagine a town, where Mrs. Ifeoluwa owns a beautiful home that she’s decided to sell. In this town, there is a strict regulatory body (comparable to Rust’s Borrow Checker) that maintains order and ensures the rules are followed. Mrs. Ifeoluwa, as the sole owner of her house, has exclusive rights to it (the principle of Ownership). She goes to the regulatory body and notifies them about her intention to sell…

Use Rust in a Node.js project

Rust is the most loved language right now — sounds like a cliche already 😃, but it’s true. In fact, it has been added to the Linux Kernel and going to be added to the Windows Kernel. Not every language enjoys that kind of privilege and love, you know. One of the benefits of Rust is that it’s fast, if you have implemented something awesome in Rust and you want…

Introducing Rust in simple English

Rust is a statically typed programming language that allows developers to build high-quality and efficient software. Rust takes memory management very seriously. While it allows you to manage your memory, it does so in a way that provides safety guarantees. Rust’s memory management system is based on the concept of ownership and borrowing. The ownership and borrowing system is a unique feature of Rust that brings together a combination of…

Rust trait implementation with a “where” clause

In today’s Rust Journey piece, we’ll discuss one concept that might confuse new Rust Developers — the where clause in the Rust trait implementation workflow. The where clause allows developers to enforce strict constraints on generic types which will result to code that is reliable, easier to maintain, and less prone to errors. While you can use the where clause in different context, our examples will be focused on how…