Cheating Higher Ranks with Traits

I ran into this a little while ago and thought it would be helpful to share a possible solution. Imagine you have an enum that describes a set of possible branches, for each branch there is a type associated with it that you want to run through a function, for this example– serialize. enum Var{One,Two,}#[derive(Serialize)]struct Foo;#[derive(Serialize)]struct Bar;fn write<W>(var: Var,mutwriter: W)-> serde_json::Result<()>whereW: Write,{matchvar{Var::One=>serde_json::to_writer(&mutwriter,&Foo),Var::Two=>serde_json::to_writer(&mutwriter,&Bar),}} Life is good. Then you realize that you actually needed to format these types in two different ways, one with to_writer and the other with to_writer_pretty. [Read More]

Rust for Java Devs

I’d like to take a change for this blog and leave the more bleeding edge topics to focus on perhaps one of the most important things one can do in the Rust community: teaching new Rust developers. I’ve been thinking about how best to approach teaching Rust to those used to working with Java, in order to bring a group of developers up to speed with the language for a new project. [Read More]

Rotary Encoders in Embedded Rust

Recently, I’ve been trying to learn more about electronics and embedded development. Maybe I’m just tired of operating purely in the virtual, but there’s something cool about being able to physically put together a circuit and push a button to make something happen. I went through the usual Arduino resources before seeing what Rust had to offer. I’m happy to report there’s some really good material out there. Discovery book Rust Embedded book Real Time For the Masses If you’re new to embedded (but not new to Rust), I’d recommend the Discovery book as your jumping off point. [Read More]

Updating to Async/Await

Unless you’ve been living under a rock; you know async/await is coming to rust stable. My last post was about implementing a simple protocol using manual futures, and interacting with tokio. It’s only fitting, then, that I update the lib that post was inspired by to async/await and report back on my findings. If you’re curious about my library or you use the window manager i3, it’s available here or on crates under tokio-i3ipc. [Read More]

Protocols in Tokio (i3 IPC)

There’s a dearth of blog posts online that cover the details of implementing a custom protocol in tokio, at least that I’ve found. I’m going to cover some of the steps I went through in implementing an async version i3wm’s IPC. Granted, I’ve not finished my library to a point I’m comfortable releasing it, but I hope I can provide some examples for the aspiring async IO enthusiast that I wish I had when I started. [Read More]

Unit Type Params

Updated: The cs140e hosted on Stanford’s servers is down, but Sergio has helpfully put up an archived copy here. I’ve changed the links in this post to reflect that. I always enjoy reading blogs about patterns or tricks people have picked up writing Rust. I’ve seen this a few times but not read about it anywhere. I’ve been doing class assignments from Operating Systems cs140e. I highly recommend this class if you know a bit of Rust and would like to try writing some lower level code. [Read More]