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…

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…

Top Companies Using Rust and their career page

Since the release of Rust first version on the 15th of May, 2015, there has been increasing adoption of Rust by major tech companies. This is a curated list of companies leveraging Rust and their career page, so, you can easily find them and apply if you need to. Amazon Amazon is one of the 5 big tech companies in the US and the largest retailer of e-commerce. They use…

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.…

Making Your Python Code Faster Using Rust

Python is an interpreted and dynamically typed programming language, that has become increasingly popular for many reasons, a few of which include its simplicity compared to other programming languages such as C, C++, and Java. It allows you to accomplish more with less code due to its wide range of libraries. Additionally, it has a very large and supportive community, making it a preferred choice for academic and research work.…

Rust mem::swap Function for Value Swapping

In Rust programming language, memory efficiency, and safety is a feature. The mem::swap function, allows you to swap values between variables efficiently. Understanding mem::swap: In Rust, the std::mem module offers a collection of functions that deal with memory-related operations. Among them, the swap function stands out as a convenient way to exchange the values of two variables. The function is designed to work with mutable references to variables, allowing for…

mem::take Vs mem::replace

mem::take and mem::replace are both used to manipulate ownership and values, but they work slightly differently. mem::take The mem::take method takes ownership of a value and replaces it with a default value of the same type. The original value is returned. Her is a simple example: In the above example, mem::take is used to take ownership of v and replace it with an empty vector and then returning the new…

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…