What is a Factory Method in Rust?
In Rust, the Factory Method is a design pattern that allows you to create objects without specifying the exact class of object that will be created. It defines an interface (or a trait in Rust) for creating objects, but the specific implementation of the object creation is left to the subclasses. This pattern promotes loose […]
What is the difference between a raw pointer and a function pointer in Rust?
A raw pointer and a function pointer are both types of pointers in programming, but they have different purposes and use cases: Raw Pointer: Function Pointer: In summary, the key differences are that raw pointers are used for general memory address manipulation and don’t carry type information, while function pointers specifically point to functions and […]
Learning Rust and improving with Codewars solutions
One of the frustrations with learning from some text books is that they set vague exercises at the end of a chapter without being explicit in the nature of the task and therefore no solution either…. For example “Write a function to convert text to ascii” Codewars Replace With Alphabet Position I’ve started to use […]
Traits #1
This is an initial example of Traits in Rust. There are more complicated examples than this but to get started this is a nice way to understand how to create a Trait and how to use it. Try the code: Try this code in Rust Playground : https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6e50061eff5ac64ceed63bd55ff767e6 Note how the definition part on line […]
How to create Public Private Keypairs in Rust
Using secp256k1 Rust bindings for Pieter Wuille’s secp256k1 library, which is used for fast and accurate manipulation of ECDSA signatures on the secp256k1 curve. Such signatures are used extensively by the Bitcoin network and its derivatives. secp256k1 This article shows the code used to create a public/private keypair using secp.generate_keypair in Rust. Also, make sure […]
How to use a Generic Struct Example: Rust Programming
In Rust rather than have to create separate structs to accept variables with different data types you can use a generic struct, eg accepting a float…or an integer. Without this, you would need to make one struct to accept u8 and one struct to f64 (if they are the 2 data types you desire). Let’s […]