Skip to content

0.7.0

Compare
Choose a tag to compare
@matsadler matsadler released this 30 Jun 21:27
· 21 commits to main since this release

Magnus 0.7.0 adds many features, but should be largely compatible with 0.6.

Magnus is a Rust library providing a high-level easy-to-use interface 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.

API changes

Magnus 0.5 and earlier would allow you to create Ruby objects with associated functions, like RArray::new. In Magnus 0.6 a new set of APIs for creating Ruby objects was added, as methods on a Ruby handle that can only be obtained on a Ruby thread. 0.7 begins the deprecation of the associated functions with the old-api feature. This feature is enabled by default, but if disabled the old-api functions will issue deprecation warnings. Disable this feature to get an early start on migrating these functions to the new API.

As part of the same effort, closures and functions used as Ruby blocks or procs now take an additional first argument of &Ruby.

The ruby-static feature has been removed. Instead enable the feature for rb-sys in your Cargo.toml like so:

rb-sys = { version = "*", features = ["ruby-static"] }

New Features

  • Support for Ruby's Thread api via methods to create threads on the Ruby type and the Thread type.
  • Support for Ruby's Mutex api via methods to create a mutex on the Ruby type and the Mutex type.
  • Support for Ruby's Fiber api via methods to create fibers on the Ruby type and the Fiber type (on Ruby versions 3.1 and up).
  • A Time type representing instances of Ruby's Time class that will convert to/from std::time::SystemTime.
  • r_array::TypedArray, a Ruby Array that may only contain elements of type T. On creation the Array is hidden from Ruby, and must be consumed to pass it to Ruby (where it reverts to a regular untyped Array). It is then inaccessible to Rust.
  • magnus::Integer now implements PartialEq, PartialOrd, Add, Sub, Mul, and Div so it can be used with mathematical operators like + and -.
  • Ruby::define_data for working with Ruby's Data class (Ruby 3.3 and up only).
  • RArray implements IntoIterator.
  • IntoError is a new trait for converting types to magnus::Error. Functions returning to Ruby can now return Result where the error type is any type that implements IntoError.

Upgrading

Upgrading from Magnus 0.6 should be straightforward. If upgrading from 0.5 or earlier, it's recommended to upgrade to 0.6 first.


See the changelog for all the changes.

Thanks

@Maaarcocr for implementing the Add et al traits for Integer.
@adampetro for contributions to the implementation of IntoIterator for RArray.
@macournoyer for fixes to Error.
@y-yagi and @gjtorikian for fixing typos.