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
Thread
api via methods to create threads on theRuby
type and theThread
type. - Support for Ruby's
Mutex
api via methods to create a mutex on theRuby
type and theMutex
type. - Support for Ruby's
Fiber
api via methods to create fibers on theRuby
type and theFiber
type (on Ruby versions 3.1 and up). - A
Time
type representing instances of Ruby'sTime
class 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::Integer
now implementsPartialEq
,PartialOrd
,Add
,Sub
,Mul
, andDiv
so it can be used with mathematical operators like+
and-
.Ruby::define_data
for working with Ruby'sData
class (Ruby 3.3 and up only).RArray
implementsIntoIterator
.IntoError
is a new trait for converting types tomagnus::Error
. Functions returning to Ruby can now returnResult
where 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.