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/ #[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(); 

Get Mastering Rust now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.