0.7.0
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
Threadapi via methods to create threads on theRubytype and theThreadtype. - Support for Ruby's
Mutexapi via methods to create a mutex on theRubytype and theMutextype. - Support for Ruby's
Fiberapi via methods to create fibers on theRubytype and theFibertype (on Ruby versions 3.1 and up). - A
Timetype representing instances of Ruby'sTimeclass that will convert to/fromstd::time::SystemTime. r_array::TypedArray, a Ruby Array that may only contain elements of typeT. 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::Integernow implementsPartialEq,PartialOrd,Add,Sub,Mul, andDivso it can be used with mathematical operators like+and-.Ruby::define_datafor working with Ruby'sDataclass (Ruby 3.3 and up only).RArrayimplementsIntoIterator.IntoErroris a new trait for converting types tomagnus::Error. Functions returning to Ruby can now returnResultwhere the error type is any type that implementsIntoError.
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.