Variables and Memory management in Rust

In every programming language, understanding how variables are stored in memory is a crucial point to make your program fast and efficient. Let鈥檚 look at how Rust does it. Note: These are quick short notes, if you want to look in deep check out rustlang docs. Ownership In programming languages, either a garbage collector is used which will clean up the memory used by the unused variables or the memory is explicitly freed by the programmer in the code....

August 5, 2020 路 6 min 路 wilspi

Structured Logging using Slog in Rust

Slog is a structured logging library for rust-lang. Structured logging is a concept that puts events over messages, events are logged with associated key-value data, not plain string messages. This helps in: processing log files for analytics searching and debugging (example: search log statements for particular user or request) Basic Logging with Slog Lets create a simple logger: #[macro_use] extern crate slog; extern crate chrono; fn main() { let drain = slog::Discard; let root_logger = slog::Logger::root(drain, o!...

August 3, 2020 路 3 min 路 wilspi

Nix Recipe: Setup Rust

This is a nix recipe for building and running rust in a virtual nix environment. Create a file rust-toolchain with following: 1.43.0 We are specifying rust version to install, here using 1.43.0. If using heroku, rust-toolchain file will determine which version will be used to build the application. Create shell.nix with following: let # Mozilla Overlay moz_overlay = import ( builtins.fetchTarball "https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz" ); nixpkgs = import (builtins....

March 4, 2020 路 2 min 路 wilspi