Monthly Archives: August 2016

Implementing an object factory pattern in Rust using closures

Coming from a Java background, I’m used to using the object factory pattern to inject behavior into an existing component. For this tutorial we’ll use the example of building a connection pool that can be used with different types of database connections. Disclaimer: The entire approach taken here might not be the best way of doing things in Rust at… Read more »

Implementing a Pratt parser in Rust

Following on from the previous tutorial that demonstrated how to¬†implement¬†a tokenizer, it is now time to implement a parser to transform the list of tokens into an Abstract Syntax Tree, hereafter referred to as an AST. We will be using a Pratt parser design, which is a recursive descent parser that is very simple to reason with. I discovered this… Read more »

Writing a Tokenizer with Iterator and Peekable

In this tutorial we will write a low-level tokenizer for tokenizing simple math expressions like “12+34*56” using Rust’s Iterator and Peekable traits. First, we need to declare some data structures for storing the results. Rust only has two types of data structure – struct and enum. If you’re coming from a Java or Scala background you would possibly be wanting… Read more »