Lessons learned redesigning and refactoring a Rust Library

Recently I've completely rewritten my GitHub API library from the ground up. One of the big reasons was to start leveraging the upcoming Hyper 0.11 release, however, the main reason I rewrote this was because I actually used my own library outside of example code and I hated using it. About a month or two or ago I started working on Thearesia a bot to manage GitHub repositories (like bors or homu). While I thought the library was okay the way I made it before, when I used it I realized how sorely mistaken I was. It was awkward…

Read More

Using an Async Hyper Client

Lately I've been revamping my GitHub API Library to be both more ergonomic and to use the upcoming 0.11 release of Hyper which is asynchronous using Futures and Tokio under the hood. Mainly this has been due to my experiences using my library in my GitHub bot Thearesia. I figured if I'm already going to be redoing how my library works might as well upgrade to the new version of Hyper as well and provide some explanations to those wishing to upgrade their own libraries. I'll be using Hyper at this commit for today's example. The docs are good…

Read More

Building an Asynchronous Hyper Server

Recently I started working on a GitHub bot similar to Bors in my spare time. I decided that I wanted to make the overhead as small as possible and to use futures to harness the power of asynchronous requests. While hyper hasn't fully switched over to this and released yet I decided to experiment with it and get a server that could take in webhook requests from GitHub and serialize it to a generic value using serde. Hopefully this helps others in the future so that they too can understand futures and what hyper has to offer. As of this…

Read More

Rust is its community

I've been thinking a lot about what Rust means to me as well as what Rust is beyond safety and speed. Recently Steve Klabnik's article, Insanity Bit's response to Steve, Dave Herman as well as Graydon's responses have got me thinking about just what Rust is as a language and what can be done to get people on board when the safety and speed pitch fail, because I've seen that happen. My coworkers know that I love Rust. So much so that I got a Rust programming book for our Secret Santa. It's a lovely language and fun to use.…

Read More

Announcing Pipers - A small library for piping commands

Back when I first started using Rust during 1.0 I had set about to learn it by writing a shell program. While the code itself is really not idiomatic (I cringed today fixing up what I took from it) it has one thing that works well. Piping commands. I've received inquiries every now and then from an old Reddit post of mine and while I did find the answer to the thread was locked so I couldn't respond leading to this scenario for some programmers. Well finals are over, this still isn't in the Standard Library for some reason…

Read More

Schemers - Parsers

Ready for the next lesson? We'll be writing our parser now, the Read in the REPL. We'll be using the nom library for parsing. It's what's known as a parser combinator library. By building small parsers that do one thing like parse a number or one that parses a string we can build them up into larger ones, for instance one that could parse a string or a number. It uses macros to build parsers. We'll start small and parse a procedure something like: (+ 3 4 5) Into a data structure we can use. By no means will our parser…

Read More

Russian Dolls and clean Rust code

Recently I started porting my website from Github pages to this domain. I wanted to make my own static site using Iron and code it all myself as a challenge rather then use a Jekyll template. The fact you're reading this means that succeeded! However, that's an article for another time. Today I wanted to talk a little about making your Rust code more readable as well as resources for better patterns and cleaner code. The Russian Doll Problem As part of the site I use a toml configuration file and I read certain values from it. Thing is with…

Read More

Schemers - Exercise 1

This post will be covering the exercises given in the first article. I'll be going over the answers and providing more idiomatic ways to do them. We'll evolve the answers to the one in the repo and cover some new concepts along the way. What we'll be covering The trim function from the String standard library module Rust use statements More match patterns Function Parameters Touching on &str Touching on enum Exercises Here's what I asked you to do in the prior post: Modify the Err line so that the program exits gracefully on an EOF or Interrupted, but…

Read More