Factory + Builder Pattern
This tutorial demonstrates the powerful combination of Factory and Builder patterns in Rust. It’s useful to know, and also be able to recognize. Key Concepts Covered: Factory Pattern: The DatabaseType enum acts as a factory that knows how to create different database implementations. It encapsulates the creation logic and provides a clean interface for object […]
Why Actors Are Perfect for WebSockets
What’s the big deal, why not use Arc and Mutex ? Actors Are Not Rust-Specific – They’re a Universal Pattern!The Actor Model is Language-AgnosticThe Actor Model was actually invented in 1973 by Carl Hewitt – way before Rust existed! It’s a conceptual framework that can be implemented in any language. The WebSocket Challenge Imagine you’re […]
Design Patterns in Rust – Singleton Pattern
The singleton pattern gives you the benefits of global access while maintaining control over how that global state is created, accessed, and modified. It’s essentially “global variables done right” for cases where you genuinely need global state. To demo this, we’ll code an example to connect to a database. This is just to make the […]
Make your own Ollama Client
Rather than use Rig.rs or Ollama-rs let’s consider the bare bones of the frameworks that we take for granted.. We make a POST reqwest to the Ollama API and send a body specifying the model and messages ( role & content ). Next – iterate over the stream and display the chunks until there are […]
Rust Workspaces
In Rust, workspaces are a way to organize multiple packages (crates) into a single project with a shared Cargo.lock and output directory (target/). This is especially useful for large projects with multiple components, such as libraries and binaries, that need to share code or build settings. 🧱 What Is a Workspace? A workspace is a […]
App state in Actix-web
AppState provides a clean, type-safe mechanism for sharing crucial resources like database connections, configuration settings, and caches across your application’s request handlers. Without it, developers would need to repeatedly establish database connections or reload configurations for each request, dramatically reducing performance and increasing complexity. By leveraging Actix-web’s AppState pattern, you create more maintainable, efficient, and […]
as_ref and Cow
Despite serving different roles, as_ref and Cow share a common goal: enabling flexibility in how data is handled, especially with respect to ownership and borrowing. Both allow your code to work with a broader range of types—as_ref by accepting inputs that can be referenced as a common type, and Cow by returning data that may […]