Skip to content

0.3.0

Compare
Choose a tag to compare
@matsadler matsadler released this 18 May 19:11
· 498 commits to main since this release

Magnus 0.3.0 adds many new features and includes a number of fixes.

Magnus is a Rust library binding to the C API of the Ruby programming language. Magnus lets you write Ruby extension libraries (or 'gems') in Rust, or embed Ruby in your Rust program.

A large portion of Ruby encoding API has been added, this includes creating Ruby strings in any encoding, converting between encodings, iterating a Ruby string's codepoints, testing a character's type, and an optimisation to RString::as_str that can avoid utf8 validity checks when that information is already known by Ruby.

Conversions between Ruby's integer and float format and the native types used by Rust has seen dramatic performance improvements, and is now on-par with C performance.

Ruby Proc objects can now be created from a Rust closure.

Many functions, plus BoxValue, that were previously stuck using the base Ruby Value type can now accept any Ruby type. Along the same lines, arguments to the closure of RHash::foreach are not longer forced to Value and can now participate in automatic type conversion.

For anyone already familiar with Ruby's C API, or taking advantage of documentation or guides assuming use of C an index has been added to the documentation mapping C functions to Rust functions in Magnus. This currently only lists the parts of Ruby's API implemented in Magnus, and is missing some cases where Magnus has equivalent behaviour, but it isn't directly implemented in terms of the C API. This will be expanded in future releases.

Many additional methods for the core Ruby classes String, Array, and Hash:

The rb-sys-interop feature swaps out the built in low-level bindings to Ruby for rb-sys and enables a module with functionality for interoperability. Future versions of Magnus will switch to rb-sys, and this feature should be considered a preview. Please give it a try and feedback is welcomed.

A handful of bugs have been fixed, including:

  • A crash when creating a StaticSymbol from a &str with characters outside the ASCII range.
  • A couple of cases where panics could cross over to Ruby with the potential for Undefined Behaviour.
  • define_*_method functions now return an error, as they are in fact fallible.

And many more changes, see CHANGELOG.md for more details.

Thanks