Text Parsing in Rust with Nom

As soon as you want to do anything non-trivial with respect to parsing text using Rust (or any language) you should use some kind of parser… Text parsing in Rust with Nom As soon as you want to do anything non-trivial with respect to parsing text using Rust (or any language) you should use some kind of parser implementation. Writing a working parser for anything but the most trivial content is non-trivial. Unless you want to learn parsers (perhaps you’re taking a compiler course), better to use an existing tool/framework. ...

July 11, 2024 · 8 min · Ray Suliteanu

Using thread locals in Rust

As I continue my journey learning Rust, I thought I’d share some learning related to multithreading and thread locals. I came across an interesting new site called CodeCrafters. The site is another learning site supporting multiple programming languages, but they focus on specific “challenges” with specific tasks to accomplish for each challenge. I’ve worked through a few of them, and I used threads and thread locals on the HTTP server challenge. ...

June 14, 2024 · 4 min · Ray Suliteanu

Creating a TUI in Rust

Way back when, before nice graphical user interfaces, all we had was the terminal. I won’t waste time with a trip down memory lane. Suffice to say there were many cool terminal-based interfaces, and some of us still use terminals (or terminal emulators more likely). And there are still nice terminal-based user interfaces used by many of us, even if that’s just vim or emacs. As I continue my journey learning Rust, I thought I’d take a stab at writing a terminal user-interface (AKA TUI). In this case I will leverage a Rust crate called ratatui. Ratatui provides UI widgets for building a TUI — things like laying out your UI, tabs, tables, scrollbars, and the like. Ratatui focuses on the UI aspects, and leverages other crates for the low level terminal interaction. Several are supported, but the one I chose (and the most common?) is called Crossterm. I am going to focus here more on Ratatui then Crossterm, except as needed. ...

May 2, 2024 · 10 min · Ray Suliteanu

Improving your error handling in Rust

This is another blog in my fledgling series on Rust as I learn the language. In this blog I touch on a few cool crates that can improve your error handling in Rust. It follows nicely from my prior post on logging in Rust. As with that post, this is just an introductory look at error handling. There is a lot more one can learn about error handling (in Rust or otherwise) than I will cover here. Here I will just touch on a few crates that can get you started. Maybe in future posts I will get into more detail on other topics, but there are also good blogs out there already (e.g. this). ...

April 13, 2024 · 5 min · Ray Suliteanu

Logging in a Rust Application

This blog post is part of a series I’m developing documenting my evolution as a Rust developer. Currently I’m a newbie, but I’m making progress. As a newbie, please feel free in the comments to elaborate on what I might be doing wrong, could do better or is not “canonical” Rust. Logging is obviously a key aspect of a production-ready application. While one could use println! or dbg! or similar Rust macros to achieve something similar, they are not really a replacement for a real logging framework. In fact, particularly for (long running) “services” as opposed to CLIs, many architecture/coding standards prohibit use of the equivalent to println! in whatever language you’re using. I myself have set such standards on projects I’ve lead. ...

April 7, 2024 · 4 min · Ray Suliteanu

There's No Such Thing as 'Regression Testing'

How would you define “regression testing”? According to Wikipedia, Regression testing (rarely non-regression testing[1]) is re-running functional and non-functional tests to ensure that previously developed and tested software still performs after a change. In the modern age of test automation and continuous integration, tests are run (or should be) automatically by the build system. Whether testing functional or non-functional features, there really are only three categories of tests to run: Unit tests Integration tests System tests Let’s discuss each in turn. ...

June 10, 2023 · 5 min · Ray Suliteanu

Building cloud software? Don't forget about this ...

When developers set out to architect a piece of software — whether a brand new green-field project or rearchitecting an existing product — the typical considerations are things like should I use microservices and how many how will these microservices communicate how will data persist what guarantees must be provided for messages flowing through the system what’s encrypted, where and when etc. Boxes and lines start appearing on whiteboards (physical or virtual) … here are the N microservices, we’ll use gRPC here, we’ll use Kafka there and MongoDb will save everything. We’ll deploy to Kubernetes, set up deployments with HPA, have at least 3 instances so our brain doesn’t get split, and monitor with the EFK stack. Great! Let’s write some code. ...

March 22, 2021 · 5 min · Ray Suliteanu

How to "group by" using Java Stream API

Recently I was trying to do essentially a “map-reduce” using the Java Stream API … counting the number of occurrences of words in some input. This wasn’t for some huge “big data” input set. Using Java Stream API was sufficient. But the Stream API doesn’t have a groupBy() operation. While it does have map() and reduce() I couldn’t add a groupBy() … at least not directly. Since it was not obvious I thought I’d write a quick post on how to do it. ...

March 12, 2021 · 4 min · Ray Suliteanu

Java's fork-join framework

Since Java 7, the JDK includes a set of classes implementing a fork-join pattern. This is an approach decomposing work into multiple tasks that can be executed in parallel. Java provides ForkJoinPool and ForkJoinTask as the two primary classes implementing the approach. This post will cover an example of using these, by converting a Mergesort implementation from a recursive implementation to one using fork-join. Mergesort is a classic divide-and-conquer approach to sorting. The data to be sorted are split into two halves, and those halves each are split into two until the data can no longer be split. Then the resulting arrays are merged and sorted. ...

January 21, 2021 · 5 min · Ray Suliteanu

Using Protocol Buffers To Serialize To Off-Heap Memory

In my previous post about Using off-heap memory in Java programs I showed how to set up a memory-mapped file. Now that we have a memory-mapped file, let’s write something to the file. There are different approaches to how to serialize Java objects obviously including the built-in Java serialization. But in this post I’m going to use Protocol Buffers (AKA protobuf) for serialization, because why not? It will also give an opportunity to show how to automate the use of protobuf in your automated build using Gradle. ...

January 2, 2021 · 4 min · Ray Suliteanu