Over the past few weeks I’ve been looking at Rust as a programming language for FRC. We decided not to use it on 5499, but I’d like to share some findings.

Building for the RIO is pretty easy to get working with arm-unknown-linux-gnueabi as the target. The trickier part is using WPILib in Rust. Bindgen can generate bindings for C and (some) C++ libraries. I couldn’t get bindings for WPILib C++ to build, but might have had success given more time. Instead, I ended up generating bindings for the HAL library (pretty much all C), and porting the C++ WPILib classes to Rust by hand. I have a proof of concept here with a stipped-down version of the AnalogInput class. This seems to work well, and you can use it with code like this:

extern crate wpilib; use std::{time,thread}; fn main() { println!("Hello world from Rust!"); let status = unsafe { wpilib::hal::HAL_Initialize(0) }; assert!(status == 0, "HAL failed to initialize!"); let input = wpilib::AnalogInput::fromChannel(1); loop { println!("Value: {}", input.get_value()); println!("Voltage: {}", input.get_voltage()); let wait_time = time::Duration::from_millis(500); thread::sleep(wait_time); } }

Let me know if your team ends up using Rust! I would love to hear more about how the season goes.