Rust Programming Language Study Notes
Rust Learning Journey
Day 1 (2021/05/27)
Explored constants, variables, data types, control flow, and ownership.
char occupies 4 bytes, equivalent to a Unicode scalar value
Control flow expressions don't require parentheses
Tuples in Rust closely resemble C++ tuple usage
// clang++ test.cpp -std=c++11 && ./a.out
#include <iostream ...
Posted on Sun, 24 May 2026 19:30:13 +0000 by stevietee
Understanding Rust Closures and the Fn Traits Hierarchy
Rust closures—anonymous, self-contained function expressions—are central to functional patterns and API design in Rust. Their behavior is governed by three core traits: FnOnce, FnMut, and Fn. These are not arbitrary distinctions but precise compile-time contracts tied to ownership, mutability, and call semantics.
Core Trait Differences
The foll ...
Posted on Sun, 24 May 2026 17:27:54 +0000 by mxicoders
Packaging BS Redis Desktop Client for Distribution
Building Release Version
Compile the Rust project using: cargo build --release
Windows Packaging
Prerequisites:
Rust toolchain
Inno Setup installer
Build steps:
Remove the comment from // #![windows_subsystem = "windows"] in main.rs
Execute cargo build --release
Place sciter.dll and the compiled executable in the same directory
Lau ...
Posted on Sat, 23 May 2026 21:42:16 +0000 by keeps21
Understanding nom::sequence::preceded in Rust
This means preceded will execute the first parser, successfully match the input, discard the first parser's result, and then continue with the second parser, returning its result.
Basic Usage Example
use nom::{
character::complete::{digit1, char},
combinator::opt,
sequence::preceded,
IResult,
};
fn parse_number(input: &str) ...
Posted on Fri, 22 May 2026 16:20:31 +0000 by purtip3154
Rust Lifetime Annotation Practices: When to Manually Specify Lifetimes
Compiler Guidance: Rust's borrow checker effectively handles lifetime inference in straightforward scenarios
Reduced Cognitive Load: Deferring explicit annotations lowers the initial learning barrier for newcomers
Limitations and Risks
Maintenance Challenges
As code complexity grows, implicit lifetime relationships become harder to manage. Ex ...
Posted on Tue, 19 May 2026 16:13:02 +0000 by johnthedeveloper
Command-Line Text Search Tool in Rust with Streaming Support
This walk-through demonstrates a small CLI utility that locates lines containing a user-supplied keyword in a text file. It automatically switches between two strategies:
For files ≤ 1 MB the entire content is loaded into memory.
For larger files it streams line-by-line to avoid high memory usage.
The tool also understands --help and reoslves ...
Posted on Sun, 17 May 2026 04:21:16 +0000 by WBSKI
Understanding Rust's Ownership Model: A Zero-Cost Memory Safety Architecture
The Architecture of Memory in Rust
In the landscape of systems programming, memory management strategies typically fall into two categories: manual management with explicit cleanup (C/C++) or automated management via garbage collection (Java, Go, Python). Rust introduces a third paradigm: a hybrid approach that ensures memory safety through com ...
Posted on Thu, 14 May 2026 11:47:24 +0000 by bkanmani
Rust Advanced Types: Newtype Pattern and Type Aliases
Newtype Pattern
The newtype pattern is a programming technique where you create a wrapper around an existing type to form a new type. This approach helps overcome certain limitations and achieve specific goals:
Abstract implementation details of a type
Hide the underlying generic type
Work around orphan rules
A common example is usin ...
Posted on Thu, 14 May 2026 04:33:25 +0000 by Chef-Mars
Resolving Linker Error LNK1181 When Using Rusqlite on Windows
When compiling a Rust application that utilizes the rusqlite crate on a Windows environment, the build process may terminate unexpectedly. The compiler output typically indicates a failure during the linking phase with exit code 1181.
The specific error message often reads:
error: linking with `link.exe` failed: exit code: 1181
= note: "LIN ...
Posted on Wed, 13 May 2026 13:53:55 +0000 by wwwapu
Understanding Rust Closures: A Deep Dive into Anonymous Functions
Introduction
After compilation, closures are transformed into standalone functions by the compiler. This is essentially a syntactic sugar provided by the language. Understanding closures is crucial for writing idiomatic Rust code.
What Are Closures?
A closure (also called an anonymous functon) is a block of code defined within a function body t ...
Posted on Wed, 13 May 2026 13:38:26 +0000 by Dilb