O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Ruby extensions with Ruru

Rust has attracted many Ruby developers. Supposedly, they are the sort of people who like languages that start with the letters ru. Seriously, though, this is good news for anyone looking for strong interoperability between these languages. A project called ruru has a nice set of helpers to make this easier. In order for all this to work, you will need to have a fairly recent Ruby installed.

Here's a minimal example of a piece of Rust code that can be called from Ruby:

// ruru_test/src/lib.rs #[macro_use] extern crate ruru; use ruru::{Float, Class, Object}; methods!(     Float,     itself,     fn sum_floats(f2: Float) -> Float {         let f1 = itself.to_f64();         let f2 = f2.expect("f2 contained an error").to_f64(); 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required