Rust string manipulations

Strings are the building blocks of text data, and being able to manipulate them efficiently is a crucial.  In this article, we’ll explore the different ways to manipulate a string in Rust with examples. There are two types of strings in Rust: string slice and String Let’s start with concatenation… Concatenation Try this code out on Rust Playground: You’ll get an error like this one: While this is a common…

Implementing a secure password reset in Node.js

Note: This article first appeared on the LogRocket blog Creating a strong password that you can actually remember isn’t easy. Users who use unique passwords for different websites (which is ideal) are more likely to forget their passwords. So, it’s crucial to add a feature that allows users to securely reset their password when they forget it. This article is about building a secure reset password feature with Node.js and Express.js. Now, let’s…

The guide to signal handling in Rust

A signal is a software interrupt sent to a process by the operating system or another process to notify it of an event. For example, when you try pressing Control+C while your program runs on a terminal, it terminates the process, correct? That’s one of the most common signals and signal handling you can see in action. We’ll explore how to handle that signal and others in Rust. A signal can be…

Understanding Closures in Rust

Like several other languages, Rust programming language supports closures also known as anonymous functions or lambda functions which is a powerful feature used for varying reasons depending on who you ask. We’ll break down closures in Rust in this article, so you can start using it in your Rust code immediately and properly. A closure in Rust is a function without a name that can be used as a variable.…

Rust’s Newtype Pattern: Adding Type Safety and Clarity

The newtype pattern is a Rust idiom that can be used to add type safety and clarity to code. At its core, the newtype pattern involves wrapping an existing Rust type (like a number or a string) inside a new struct. This might seem unnecessary at first, but the magic is that this new struct becomes a distinct type and ensures that you are using the correct type where necessary.…

Building a simple Rust webserver

What comes to mind when you think of building a web server with Rust? I bet you think of using Axum, Rocket, Actix, etc., right? These are mature frameworks for building web applications with Rust. By the end of this article, we’ll learn how to build a web server of our own that will receive a get or post request and respond to it without any of those shiny frameworks.…

Mem::replace in Rust

mem::replace is a Rust standard library function that swaps a value in a variable with a new value while returning the original value. In Rust, when you move data out of a container like Vec or Option, the container can no longer be directly used, as its contents have been moved and it is considered empty or invalidated. Imagine a scenario where you want to take the data out of…

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…

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…