Dereference
In Rust, the dereference operator (*) is crucial when working with references to access the underlying values. It is especially relevant in scenarios involving borrowed data, such as when iterating over collections like arrays or vectors. When using iterators, like in a for loop, the iterator provides references to the elements, requiring the dereference operator […]
Generic Type Parameters in Rust
Introduction: Unlock the power of generics in Rust with this concise code example. Learn how to define and leverage generic types using the Query struct, which takes a flexible type parameter T. The accompanying meh function showcases the versatility of generics by accepting a Query<i32> instance. Discover the elegance and expressiveness of Rust’s generic programming […]
This should not compile?
Should this compile, my initial expectation was that it would not….. In Rust, moving a value out of a Box or any other owned container is allowed, but it doesn’t invalidate the original variable (v in this case). The variable v is still in scope, and you can continue using it. However, when you print […]
Musl – static linking
I have a chat with chatGPT about Musl, static linking, libc.so.6 and dereferencing smart pointers…here is the conversation! is it possible to make a rust program that prints it’s main.rs and shows what variables live on the stack and which live on the heap? In Rust, it’s not straightforward to inspect the stack and heap […]
Rust – use an upstream crate
How to write your own library and import it from GitHub, via Cargo.toml
🟩 Rust, main.rs is typically used for the entry point of standalone executables, containing the main function. lib.rs is for library code, providing reusable functionality. When building a binary, main.rs is used; for libraries, lib.rs holds the central module.
Dissecting a Rust Program | Axum & Sled
I’ve chosen a project on GitHub to pick apart and study to learn some new code, crates and ideas. The project is : https://github.com/kyoheiu/url-shortener-axum-sled I chose it because I want to learn more about Sled as it’s recommended to be used with BDK (Bitcoin Development Kit) First, let’s have a look at Cargo.toml and see […]
Understanding Rust’s From Trait
In Rust, the From trait plays a crucial role in allowing the conversion of one type into another. Let’s explore this concept through a straightforward example involving the conversion of lengths from feet to meters. Struct Definitions Here, we have two structs, Feet and Meters, each representing a length in a different unit. From Trait […]