Avoiding Logic Bugs in Rust with Traits and Types

The other day I saw someone comment how a bug could have been avoided if Rust was used. This was incorrect as it was a logic bug not a memory bug. Rust guarantees memory safety, but whether your logic is correct is a whole different story. That being said we can use Rust's type system to make our code work and avoid logic bugs. Rust has some nice abstractions to avoid these kinds of errors if used properly. Is it perfect? No, if they're implemented incorrectly then you're still going to have logic bugs. If your implementation is correct though…

Read More

Global Uninitialized Statics in Rust

Before we jump into things I want to put the following disclaimer: Uninitialized Global Statics are generally not what you want to have in Rust. In fact if this is the first thing you're reaching for you might want to rethink your design. Why though? If it's uninitialized you then need to give it some value later meaning the static variable needs to be mutable which is not thread safe if accessed later after being created. If a static variable changes throughout the lifetime of the program then Rust can't guarantee you won't have different results. If you need things…

Read More

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