Downcasting Traits in Rust
Why and how to downcast a trait object to a concrete type in Rust.
Read More
JWT Validation in OpenResty
Learn how to validate JSON Web Tokens (JWT) in OpenResty using the lua-resty-jwt library. This post covers the basics of JWT, token validation, and how to integrate JWT validation into your OpenResty application.
Read More
Understanding Borrowing in Closures and Variable Capturing in Rust
Closures in Rust capture variables from their surrounding environment using one of three methods: by reference (&T), by mutable reference (&mut T), or by value (T). The capture method is inferred by the compiler based on how the closure uses the variable. Closures can implement one of three traits (Fn, FnMut, or FnOnce), depending on whether they read, modify, or consume the captured variable. The move keyword forces ownership of variables into the closure, which is essential for async tasks and multi-threaded contexts. This article provides detailed examples of these concepts, highlighting key distinctions between borrowing, mutability, and capture mechanics.
Read More
Understanding Borrowing and Lifetimes in Rust
Rust's borrowing and lifetime rules ensure memory safety without garbage collection. This post explores shared and exclusive borrows, lifetime management, and the role of the borrow checker in preventing data races and dangling references using some basic examples.
Read More
Trait Bounds in Rust
Learn how to use trait bounds in Rust to write flexible and reusable code. This post covers defining trait bounds, combining multiple constraints, using where clauses for readability, and handling Rust’s orphan rule with wrapper types.
Read More
Phantom Types in Rust
Learn how phantom types in Rust enable compile-time guarantees without runtime overhead. This post explains how to use PhantomData to track type-level information, enforce state transitions, and create safer, more robust APIs.
Read More