Welcome to Ported Security. Time to learn!
Rust: CLI Tutorial, Building Your First Command Line Tool
Over the past nine steps, you have went over variables, memory ownership, control flow, custom data types, collections, error handling, and file organization. Today, we are going to combine those concepts into a single, functional Command Line Interface (CLI) application. Our project will be a System Scanner. It will accept a file name from the terminal, open and read that file, parse the data into custom Structs, and output a formatted report. ...
Rust: Modules and Traits, Organizing Code and Shared Behavior
When you first start learning to program, it is perfectly normal to dump all your variables, functions, and structs into a single file. But as your application grows from a small script into a fully-fledged system, a 1,000-line main.rs file becomes a nightmare to navigate. To build scalable software, you need two things: a way to split your code into multiple files, and a way to define shared behaviors across different custom data types. ...
Rust: Collections, Mastering Vectors and Strings
So far in this series, we have worked with data types that have a fixed size known at compile time, like a u32 integer or a boolean. These are fast and stored neatly on the “Stack.” But what if you are building an application where you don’t know how much data you will have until the program is actually running? If you are building a To-Do list, you don’t know if the user will add 3 items or 300. ...
Rust: Error Handling, Ditching Exceptions for Result and Option
In many programming languages, errors are treated as an afterthought. If a file is missing or a network request fails, the language throws an “Exception,” abruptly halting the normal flow of the program. If you forget to wrap that code in a try/catch block, your entire application crashes. Worse still is the billion-dollar mistake: the null value. Trying to access a value that happens to be null is a leading cause of software crashes worldwide. ...
Rust: Pattern Matching, Mastering the Match Operator
In our previous post, we explored how to model custom data using Enums, allowing a value to be exactly one of several distinct variants. But once you have data locked inside an Enum, how do you extract it and make decisions based on it? You could use a long, messy chain of if and else if statements. However, Rust provides a tool that is elegant and powerful, it will change how you write logic, the match operator. ...
Rust: Structs and Enums, Modeling Custom Data
So far, we have worked with primitive data types: integers, booleans, and strings. While these are the building blocks of software, they are rarely enough to model real-world concepts on their own. If you are building an MMO server, a character is not just a String or a u32. A character is a complex entity with health, power reserves, a specific role, and an inventory. Managing all these distinct variables separately would quickly turn your code into an unreadable mess. ...
Rust: Ownership Explained, Memory Safety
If you have ever spent hours digging through Windows Error Reporting logs trying to decipher a sudden BEX64 crash, or watched an application completely lock up due to a mysterious memory access violation, you have been the victim of poor memory management. In traditional systems programming languages like C or C++, developers have to manually allocate and free memory. If they forget to free it, the program bloats and crashes (a memory leak). If they free it too early and try to use it again, the application violently terminates (a use-after-free error, often throwing that dreaded 0xc0000005 exception code). ...
Rust: Control Flow, Making Decisions with If, Else, and Loops
Programs are not just top-to-bottom lists of instructions. For software to be useful, it needs to react to data, make decisions, and repeat tasks. A game needs to keep running until the player quits. A server needs to respond differently to an admin than to a guest. The mechanisms that guide a program through these decisions are called Control Flow. Let’s go over how Rust handles branching logic (if/else) and repetition (loops). We will also build a classic beginner project: a number-guessing game that utilizes an infinite loop and conditional breaking. ...
Rust: Variables and Immutability
If you are coming to Rust from languages like Python, JavaScript, or C++, you are used to variables acting exactly as their name implies: they vary. You declare a variable, assign it a value, and change that value whenever the program’s logic dictates. Rust takes a different, highly intentional approach. In Rust, variables are immutable by default. Once a value is bound to a name, you cannot change it. This might feel restrictive at first, but it is one of the foundational design choices that allows Rust to guarantee memory safety and thread safety without sacrificing speed. Let’s explore how variables work in Rust, why immutability is the default, and how to safely bypass it when you need to. ...
Rust: Cargo and the Anatomy of "Hello, World"
Welcome to day one of writing Rust. You are stepping into a language that powers everything from massive web servers to the core utilities of operating systems. If following from our previous post, you are ready to dive right in. Otherwise, checkout Setting up your development environment . Let’s start with a break down on how Rust projects are structured and get your first program off the ground. Meet Cargo: Your New Best Friend In some languages, compiling code, managing dependencies, and formatting your files require three or four different tools. Rust simplifies this with Cargo. ...