0.3.0
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
:
RString::new_shared
RString::new_frozen
RString::enc_new
RString::enc_coderange
RString::codepoints
RString::char_bytes
RString::len
RString::length
RString::is_empty
RArray::dup
RArray::concat
RArray::plus
RArray::delete
RArray::delete_at
RArray::resize
RArray::reverse
RArray::rotate
RArray::sort
RHash::delete
RHash::clear
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
- @ianks for rb-sys.
- @bbugh for a comment on Reddit and some benchmarks that helped me find some inefficiencies in number conversions.
- @briankung for some improvements to documentation.
- @ms-jpq for a fix compiling to Linux aarch64.
- @dylanahsmith for a comment on an unrelated PR that helped me spot some potential Undefined Behaviour in Magnus.