magnus
High level Ruby bindings. Write Ruby extension gems in Rust, or call Ruby code from a Rust binary.
0.8.2
5.6M downloads/mo
#4297 most downloaded on crates.io
matsadler/magnus
What this package is like to depend on
Last release 10 months ago
08 Oct 2025
Ships unpredictably
gaps range from 2 weeks to 1.2 years
Nearly every release is documented
notes for 26 of 27 stable releases
Nothing withdrawn
no release was ever pulled
4 years old
27 releases · first in 2022
2 releases in the last 12 months
see the full history below
Release timeline
27 releases · Feb 2022 to Oct 2025Releases
latest 27-
0.8.208 Oct 2025Release notes
Open source →Magnus 0.8.2 is a patch release, with 1 bug fix.
Fixes an incorrect error message when converting a Ruby string to a Rust string fails. Thanks to @jeffcharles for this fix.
See the 0.8.0 release for what's new in 0.8.
-
0.8.106 Sep 2025Release notes
Open source →Magnus 0.8.1 is a patch release, with 1 bug fix.
Fixes a compilation error on 32-bit platforms. Thanks to @jonian for reporting this issue.
See the 0.8.0 release for what's new in 0.8.
-
0.8.026 Aug 2025Release notes
Open source →Magnus 0.8.0 adds a handful of features and fixes. The
old-apifeature introduced in 0.7.0 is no longer a default feature, so functions marked as part of the old API will be deprecated by default. Otherwise it is largely compatible with 0.7.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.
Fixes
- The
fatalexception raised when a Rust function bound to Ruby panics can no longer be caught withrescue Exception. - Fixed type bounds for
TryConvertOwnedfor(T, ...)so thatTmust beTryConvertOwned.
API changes
The minimum supported Rust version in now 1.65.
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 aRubyhandle that can only be obtained on a Ruby thread. The older associated functions API is now marked as deprecated by default. Theold-apifeature can be enabled to disable deprecation warnings for the old API. In a future version of Magnus will remove this feature.The
FStringtype has been removed as it can not safely uphold the promise it was making. Either due to Ruby's apis changing or a misinterpretation of old documentation it had been designed assuming interned strings (aka 'fstrings') would not be garbage collected, which is not the case.Conversions between Ruby's
Timeand Rust'sSystemTimenow preserve nanosecond precision.RString::to_stringwill now use a Ruby utf-8 validation api that caches the results of the validity check. This will greatly improve performance in the case a string is already known to be utf-8, but may slightly reduce performance when not known.New Features
Ruby::time_nano_new,Ruby::time_timespec_new, andTime::timespec.- The
chronofeature can be enabled to allow automatic conversions betweenchrono::DateTime<Utc>andchrono::DateTime<FixedOffset>and RubyTimeobjects. typed_data::Writebarrier::writebarrierandwritebarrier_unprotect.- Automatic type conversions for
NonZerotypes,i128/u128, andBTreeMap. Ruby::io_extract_modeenc.
Upgrading
Upgrading from Magnus 0.6 or 0.7 should be straightforward. If upgrading from 0.5 or earlier, it's recommended to upgrade to 0.6 first.
FromIteratorforRArrayandRHashare hidden behind theold-apifeature (which will be removed in a future version of Magnus). UseRuby::ary_from_iterandRuby::hash_from_iterrather thanRArray/Rhash::from_iterorcollect::<RArray>()/collect::<RHash>().
See the changelog for all the changes.
Thanks
@ankane for implementing
TryConvertforNonZerotypes,i128/u128support, and some additional improvements.
@emwalker for thechronofeature.
@erickguan for improvements to docs, some fixes, and IO features includingRuby::io_extract_modeenc.
@ianks and @sandbergja for other fixes.
@yaroslav for a detailed issue report that lead to an improvement.Release notes
Open source →Added
Ruby::time_nano_new,Ruby::time_timespec_new, andTime::timespec.- The
chronofeature can be enabled to allow automatic conversions betweenchrono::DateTime<Utc>andchrono::DateTime<FixedOffset>and RubyTimeobjects. typed_data::Writebarrier::writebarrierandwritebarrier_unprotect.- Implement
TryConvertforNonZerotypes. iomodule available withiofeature, supportingio_extract_modeenc,OpenFlags,FMode, andIoEncoding.Ruby::io_extract_modeenc, a safe wrapper aroundrb_io_extract_modeenc, allowing structured extraction of open flags, mode flags, and IO encoding metadata.OpenFlagsstruct, which wraps Ruby'sO_open flags (e.g.O_RDONLY,O_CREAT) in a convenient bitflag-like interface.FModestruct, representingFMODE_flags used internally by Ruby to represent IO modes (READ,WRITE,BINARY_MODE, etc.).IoEncoding, a safe Rust struct for temporarily owning and inspectingrb_io_encoding, including safe accessors for internal/external encoding and encoding options.- Automatic type conversions to/from
i128/u128. to_i128/to_u128forFixnum/Bignum/Integer.Ruby::integer_from_i128&Ruby::integer_from_u128.RHash::to_btree_mapand automatic conversion fromHashtoBTreeMap.
Changed
- Minimum supported Rust version is now 1.65.
- Conversions between Ruby's
Timeand Rust'sSystemTimenow preserve nanosecond precision. - 'old-api' feature, which disables deprecation warnings for the old api is no longer a default feature.
RString::to_stringwill now use a Ruby utf-8 validation api that caches the results of the validity check. This will greatly improve performance in the case a string is already known to be utf-8, but may slightly reduce performance when not known.RString::to_interned_strnow returns anRStringrather than anFString.
Deprecated
thread_fd_closeas it will be a no-op as of Ruby 3.5
Removed
FStringas it can not safely uphold the promise it was making. Either due to Ruby's apis changing or a misinterpretation of old documentation it had been designed assuming interned strings (aka fstrings) would not be garbage collected, which is not the case.RString::as_interned_stras its only purpose was to return anFString.
Fixed
- The
fatalexception raised when a Rust function bound to Ruby panics can no longer be caught withrescue Exception. - Fixed type bounds for
TryConvertOwnedfor(T, ...)so thatTmust beTryConvertOwned. - Defining functions with an arity of 16
- The
-
0.7.130 Jun 2024Release notes
Open source →Magnus 0.7.1 is a patch release, with 1 documentation fix.
Fixes building docs against Ruby 3.0. This should resolve building docs for docs.rs.
See the 0.7.0 release for what's new in 0.7.
-
0.7.030 Jun 2024Release notes
Open source →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 aRubyhandle that can only be obtained on a Ruby thread. 0.7 begins the deprecation of the associated functions with theold-apifeature. This feature is enabled by default, but if disabled theold-apifunctions 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-staticfeature has been removed. Instead enable the feature forrb-sysin 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
Addet al traits forInteger.
@adampetro for contributions to the implementation ofIntoIteratorforRArray.
@macournoyer for fixes toError.
@y-yagi and @gjtorikian for fixing typos.Release notes
Open source →Added
Thread,Ruby::thread_create/thread_create_from_fnand other thread APIs.Mutex,Ruby::mutex_newand other mutex APIs.Fiber,Ruby::fiber_new/fiber_new_from_fnand other fiber APIs (requires Ruby >= 3.1).Ruby::ary_try_from_iteris an efficient way to create a Ruby array from a fallible Rust iterator.Ruby::hash_from_iterandRuby::hash_try_from_iter.RFileimplementsAsRawFd.TypedArray<T>, 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.- Implement
IntoIteratorforRArray. - Implement
PartialEq,PartialOrd,Add,Sub,Mul, andDivforInteger. Timewith automatic conversion to/fromstd::time::SystemTime.Ruby::alias_variable.Ruby::waitpid.RHash::lookup2.Ruby::define_datanew for Ruby 3.3.IntoErrortrait for conversion toError, plusimpl ReturnValue for Result<T, E> where E: IntoErrorto allow returning custom error types to Ruby.
Changed
- Closures/Functions used as Ruby blocks/procs take an additional first
argument of
&Ruby.
Deprecated
RArray::each. Please useary.into_iter()orary.enumeratorize("each", ())instead.
Removed
deprecated-send-sync-valuefeature.ruby-staticfeature. Instead enable the feature forrb-sysin your Cargo.toml like so:rb-sys = { version = "*", features = ["ruby-static"] }typed_data::Obj::get.- The
QTRUE,QFALSE, andQNILconstants. Class::undef_alloc_func.Value::try_convert.Binding.gc::{mark, mark_slice, mark_movable, location}.RStruct::as_slice.Exception::backtrace.
Fixed
Security
- Support for Ruby's
-
0.6.409 May 2024Release notes
Open source →Magnus 0.6.4 is a patch release, with 1 fix.
Lazycould deadlock when called for the first time from multiple threads simultaneously.The fix for results in a slight change in expected behaviour. If multiple threads attempt first access at the same time the
funcgiven toLazy::newmay be called more than once, but all threads will receive the same value.Thanks to @choubacha for reporting this issue, along with an excellent repro.
Release notes
Open source →Fixed
- Potential deadlock in
Lazywhen accessed for the first time from multiple threads simultaneously.
- Potential deadlock in
-
0.6.301 Apr 2024Release notes
Open source →Magnus 0.6.3 is a patch release, with 1 fix.
Adds missing
IntoValueFromNativeimplementations forVecandHashMap. This was preventing converting nestedVecs to Ruby Arrays. See issue #105.Thanks to @Vagab for reporting this issue.
-
0.6.219 Sep 2023Release notes
Open source →Magnus 0.6.2 is a patch release, with 1 fix.
Fixes a compile error using the
bytesfeature. See issue #90.Thanks to @jwilm for reporting this issue.
-
0.6.120 Aug 2023Release notes
Open source →Magnus 0.6.1 is a patch release, with 1 change.
This release adds support for
rb-sys' stable-api feature.Thanks to @gmalette for this change.
-
0.6.029 Jul 2023Release notes
Open source →Added
value::Opaquecan be used to wrap a Ruby type to make itSend+Sync.value::Lazylazily initialises a Ruby value so it can be assigned to astatic.value::OpaqueIdis aSend+Syncversion ofvalue::Id.value::LazyIdis anIdwith aconstconstructor so can be assigned to astaticand derefs toOpaqueId.error::OpaqueErroris aSend+Syncversion ofError.- The
#[magnus(opaque_attr_reader)]attribute can be set onOpaquewrapped fields of a struct when derivingTypedDatato generate a method to return the inner value. Ruby::initfunction to initialise Ruby when embedding Ruby in Rust that runs a function with Ruby initialised, passing&Ruby.rb_assert!()macro to assert a Ruby expression evaluates to a truthy value.Class::undef_default_alloc_functo remove a class' allocator function only if it is Ruby's default allocator function.Class::obj_allocandClass::define_alloc_funcfor allocating an object without callinginitialize, and for defining an allocator function.RTypedData::wrap_as&typed_data::Obj<T>::wrap_ascan be used to dynamically set the class when wrapping Rust data in a Ruby object. This can be used to allow wrapped data to be subclassed in Ruby.Exception::exception_classreturns the class of an exception as anExceptionClass.- The
kwargs!()macro andKwArgstype can be used to pass keyword arguments toReprValue::funcall, et al.
Changed
- Minimum supported Rust version in now 1.61.
- The
bytes-cratefeature has been renamed tobytes. - The
rb-sys-interopfeature has been renamed torb-sys. - Ruby types are no longer
SendorSync. These types can be madeSend&Syncwith thedeprecated-send-sync-valuefeature. This feature is meant to ease upgrading and will be removed with the next release. Value's methods moved to theReprValuetrait.typed_data::Obj<T>derefs toTso nowT's methods can be called directly ontyped_data::Obj<T>.ReprValueandTryConvertadded tomagnus::prelude.typed_data::Cmp,typed_data::Dupandtyped_data::Inspecttraits to help with implementing#<=>,#dup&#clone, and#inspectmethods for wrapped structs.- Wrapped data must be
Syncto enablefrozen_shareableflag. TypedData::classandTypedData::class_fornow take a&Rubyargument.DataTypeFunctions::markandDataTypeFunctions::compactnow take&gc::Markerand&gc::Compactorarguments respectively.- Init function marked with
#[magnus::init]optionally takes a&Rubyargument. - Functions bound as Ruby methods with
method!()andfunction!()optionally take&Rubyas a first argument. - The value returned from
embed::initderefs toRuby. DataTypeBuilder::new/DataType::buildernow take theirnameargument as a'static CStr(see themagnus::data_type_builder!macro to construct aDataTypeBuilderwith a'static CStrname).- All methods on
DataTypeBuilderare nowconst, soDataTypecan be constructed in aconstcontext and be assigned to astatic. - The
#[wrap]and#[derive(TypedData)]macros now support setting the#[magnus(unsafe_generics)]attribute to allow derivingTypedDatafor types with generics. The derived implementation is not guaranteed to be correct.
Deprecated
typed_data::Obj::getas it is made redundant by theDerefimplementation fortyped_data::Obj.- The
QTRUE,QFALSE, andQNILconstants. Please usevalue::qtrue(),value::qfalse(), andvalue::qnil(). Class::undef_alloc_func. Please useClass::undef_default_alloc_func.Value::try_convert, preferTryConvert::try_convertorT::try_convert.Binding. To call methods on Ruby's binding, useReprValue::funcallon aValueknow to be an instance of Ruby's Binding class.gc::{mark, mark_slice, mark_movable, location}, instead usegc::Marker::{mark, mark_slice, mark_movable}andCompactor::location.RStruct::as_slice.
Removed
- Inherent methods on
RClass, importmagnus::Classtrait ormagnus::prelude::*. Into<Value>/From<T> for Valueimplementations, useIntoValue.Defaultimplementations forValue,RClass, andExceptionClass.Errorcan no longer be directly constructed, must useError::neworError::from/Exception::into.RString::append(useRString::buf_append).Error::runtime_error(useError::new(exception::runtime_error(), msg)).
Fixed
RFloat::from_valuenow returnsNonewhen value is aFlonum.
-
0.5.520 Aug 2023Release notes
Open source →Magnus 0.5.5 is a patch release, with 1 change.
This release adds support for
rb-sys' stable-api feature. This necessitates upping the minimum supported Rust version to 1.60.Additionally, Ruby 2.6 support requires enabling
rb-sys'stable-api-compiled-fallbackfeature in yourCargo.tomllike so:rb-sys = { version = "*", default-features = false, features = ["stable-api-compiled-fallback"] }
Release notes
Open source →Changed
- Support
rb-sys'stable-apifeature. - Minimum supported Rust version is 1.60.
- Ruby 2.6 support requires enabling
rb-sys'stable-api-compiled-fallbackfeature in yourCargo.tomllike so:rb-sys = { version = "*", default-features = false, features = ["stable-api-compiled-fallback"] }
- Support
-
0.5.408 Jun 2023Nothing published for this version
-
0.5.308 Apr 2023Release notes
Open source →Added
Value::as_valuemethod that can be called on any Ruby type (as all Ruby types deref toValue) as a forward-compatible way to convert a Ruby type toValue.
-
0.5.219 Mar 2023 -
0.5.118 Feb 2023 -
0.5.011 Feb 2023Release notes
Open source →Added
typed_data::Obj<T>, a Ruby object wrapping a Rust type known to beT.RArray::to_ary,RArray::assoc,RArray::rassoc, andRArray::cmp.RHash::with_capacitynew for Ruby 3.2.RHash::bulk_insert.Value::hashto generate a hash key for a Ruby object.typed_data::Hashandtyped_data::IsEqltraits to help with implementing#hashand#eql?methods for wrapped structs.- Lots of
RStringmethods:capacity,cmp,comparable,drop_bytes,dump,ellipsize,offset,plus,times,replace,scrub,shared_replace,split,update. RRegexp::new/new_str,RRegexp::reg_match, andRRegexp::options.- The
backref_getfunction to get theRMatchfor the last regexp match. RMatch::nth_defined,RMatch::nth_match,RMatch::backref_number,RMatch::matched,RMatch::pre,RMatch::post, andRMatch::lastRBignum::is_positive/is_negative.new,num, anddenforRRational, plusrationalizeandrationalize_with_precforFloat.RComplex::new,polar,real,imag,conjugate,abs&arg.- New
Numerictrait implemented forInteger,Float,RRational,RComplex, etc. Exposes functions for applying operators to numeric types following Ruby's coercion protocol. value::Id::newadded to replacevalue::Id::from.TypedData::class_forcan be implemented to customise the class on a case by case basis when wrapping Rust data in a Ruby object.- The
#[wrap]and#[derive(TypedData)]macros now allow setting#[magnus(class = "...")]on enum variants to customise the class per variant when wrapping enums in a Ruby object. Value::funcall_publiccalls a public method, returning an error for a private or protected method.error::Result<T>is shorthand forstd::result::Result<T, Error>.embed::setupto perform minimal initialisation of Ruby for environments whereembed::initdoesn't work.- The
bytes-cratefeature can be enabled to allow automatic conversions betweenbytes::Bytesand Ruby strings.
Changed
- When converting Ruby values to
RArray(orVec<T>,[T; 1], or(T,)), an error will be returned if given a non-Array(or non-to_ary-able) value, rather than wrapping it in an array (seeRArray::to_aryfor the old behaviour). r_typed_data::{DataType, DataTypeFunctions, DataTypeBuilder, TypedData}all moved totyped_datamodule,r_typed_datamodule removed. This should only affectDataTypeBuilderas it was the only one not exported at the crate root.gc::adjust_memory_usage's argument changed toisize, rather thani32ori64depending on pointer width.- The
IntoValuetrait is now used instead ofInto<Value>for converting to Ruby types. IntoId,IntoRString, andIntoSymbolare used instead ofInto<Id>,Into<RString>, andInto<Symbol>.use magnus::prelude::*will now import traits anonymously.EncodingCapable,Module,Class, andObjecttraits can no longer be implemented by user code.- The
wb_protectedflag is automatically set for data wrapped in a Ruby object whenmarkis not set.
Deprecated
RString::append(useRString::buf_append).Error::runtime_error(useError::new(exception::runtime_error(), msg)).- Implementations of
Into<Value>(useIntoValue).
Removed
DataTypeBuilder::free_immediatly(usefree_immediately).From<&str> for RString/Into<RString> for &str.From<String> for RString/Into<RString> for String.From<&str> for Symbol/Into<Symbol> for &str.From<String> for Symbol/Into<Symbol> for String.From<&str> for StaticSymbol/Into<StaticSymbol> for &str.From<String> for StaticSymbol/Into<StaticSymbol> for String.From<&str> for Id/Into<Id> for &str.From<String> for Id/Into<Id> for String.- Internal
debug_assert_value!()macro no longer public.
Fixed
- Missing
ReprValueimplementation forRStruct.
-
0.4.424 Dec 2022Release notes
Open source →Added
Class::undef_alloc_func, a function to remove a class' allocator function.
Fixed
- 'wrapped' structs from
#[wrap]and#[derive(TypedData)]macros will not generatewarning: undefining the allocator of T_DATA classunder Ruby 3.2
-
0.4.308 Dec 2022 -
0.4.230 Nov 2022 -
0.4.130 Nov 2022Release notes
Open source →Fixed
scan_args::get_kwargserror/segfault when leading optional args were not provided, due to trying to convert the type of the missing value.
-
0.4.019 Nov 2022Release notes
Open source →Added
Value::funcall_with_block.- impl
TryConvertforExceptionandExceptionClass. Classtrait (implemented forRClassandExceptionClass).define_errorandModule::define_errorhelpers for defining an Exception Class.RTypedData::wrapandRTypedData::getinherent methods for wrapping Rust types in Ruby objects.- Support for Ruby 3.2 preview.
- Support for mswin platform (msvc) on Windows with Ruby 3.2 (in addition to the mingw support previously available for all Ruby versions on Windows).
Changed
- Switched to rb-sys for low level bindings.
- Rust types wrapped in Ruby objects must be
Send. - Only function pointers (fn or non-capturing closure) are accepted as argument
for
Value::block_call. UseProc::from_fn+Value::funcall_with_blockfor closures that capture variables. Proc::newonly accepts a function pointer, useProc::from_fnfor closures that capture variables.ExceptionClass::default()now returnsStandardErrorrather thanRuntimeError.TryConvertnow takesValueby value (rather than a reference).
Deprecated
DataTypeBuilder::free_immediatly(usefree_immediately).free_immediatlyattribute inwrapmacro (usefree_immediately).free_immediatlyinmagnusattribute ofderive(TypedData)macro (usefree_immediately).
Removed
String::encode_utf8, user_string.conv_enc(RbEncoding::utf8())instead.Value::leak, usegc::register_mark_objectinstead.define_global_variable(usedefine_variable).
Fixed
- Memory leak of the message when returning an
Errorto raise an exception. Flonumsupport disabled for Ruby built with USE_FLONUM=0 (e.g. 32 bit systems).- Correct spelling of
free_immediatly(tofree_immediately) in theDataTypeBuilderstruct, andwrapandderive(TypedData)macros.
Security
printf-style format strings no longer interpreted in error messages when automatically raised as Ruby exceptions.
-
0.3.230 May 2022Release notes
Open source →Fixed
- Better error output from build script when
rubycan't be found or errors. - Fixed crash in
Proc::newandValue::block_callwhen the proc was stored and called later.
- Better error output from build script when
-
0.3.122 May 2022 -
0.3.018 May 2022Release notes
Open source →Added
RString::new_sharedandRString::new_frozen.encodingmodule, includingencoding::IndexandRbEncodingtypes.RString::enc_coderangeand related methods.RString::codepointsandRString::char_bytesiterators over string contents.- The following methods for
RArray:dup,concat,plus,delete,delete_at,resize,reverse,rotate, andsort. - New methods for
RString:enc_new,len,length, andis_empty. RHashgains the methodsdeleteandclear.require,current_receiver,call_super, anddefine_global_constfunctions.Object::singleton_classandObject::extend_object.Proc::new,Proc::arity, andProc::is_lambda.superclassandnamemethods forRClass.scan_args::check_arity.- Methods for
Module:include_module,prepend_module,const_set,ancestors,define_attr, anddefine_alias. rb-sys-interopfeature to use low level bindings from rb-sys, andrb_sysmodule to expose functions for working with rb-sys.- Added
gc::register_mark_object,gc::register_address,gc::unregister_address,gc::count,gc::stat, andgc::all_stats. Error::iter_break.StaticSymbol::checkandId::checkto check if a symbol exists.
Changed
RArray::cat,RArray::from_slice, andgc::mark_slicewill accept a slice of any Ruby type as an argument, rather than only a slice ofValue. This may change type inference rules such that things likeRArray::from_slice(&[1.into()])will no longer work. UseRArray::from_slice(&[Value::from(1)])instead.- Similar to above,
gc::locationwill accept any Ruby type as an argument. BoxValuecan hold any Ruby type, not justValue.- Improved performance for conversion between Ruby floats/integers and Rust types.
- The parameters to the closure passed to
RHash::foreachwill now be automatically converted fromValueto Rust types. Module::define_method,Module::define_private_method,Module::define_protected_method,RModule::define_singleton_method, andObject::define_singleton_methodall returnResult<(), Error>rather than()as they may fail in the unusual case that the receiver is frozen.
Deprecated
String::encode_utf8, user_string.conv_enc(RbEncoding::utf8())instead.Value::leak, usegc::register_mark_objectinstead.define_global_variable(usedefine_variable) to better match Ruby C API naming.Exception::backtrace, useex.funcall("backtrace", ())instead.
Removed
error::protectremoved as it should not be needed when using Magnus. For use with rb-sys enable therb-sys-interopfeature and usemagnus::rb_sys::protect.Qfalse::new,Qnil::new,Qtrue::new,Qundef::new(use QFALSE/QNIL/QTRUE/QUNDEF).- Functions for generating an
Errorwith a specific Ruby type. E.g.Error::type_error("..."), useError::new(exception::type_error(), "...").
Fixed
- creating a
StaticSymbolfrom a&strwith characters outside the ASCII range. - panicking in any of the functions of
DataTypeFunctionswill abort the process to avoid undefined behaviour. - panicking in the closure passed to
RHash::foreachwon't result in undefined behaviour.
-
0.2.103 Apr 2022Release notes
Open source →Fixed
- Fixed compilation error in
method!andfunction!macros with arity argument of 5.
- Fixed compilation error in
-
0.2.001 Apr 2022Release notes
Open source →Added
- Functions in
class,module, anderrormodules to access built-in classes/modules. - Many doc examples.
RArray::len,RArray::includes,RArray::join,RArray::is_shared,RArray::replace, andRArray::subseq.- Implement
From<&str>andFrom<String>forRString. - Support for
Range. - Pre-built bindings for Ruby 3.1 on Windows.
- Support calling Ruby methods with Rust closure as a Ruby block.
Class::newandModule::newfor creating anonymous classes/modules.r_string!macro to create Ruby string from astrliteral.Value::equalandValue::eqlfor object equality.Value::respond_toandValue::check_funcallfor conditionally calling Ruby methods only when they are defined.scan_argsandget_kwargsfor complex argument parsing.
Changed
Qundef::to_valuenow markedunsafe.RArray::cat,RArray::push,RArray::unshift, andRArray::storenow returnResult<(), Error>.eval!macro uses anonymous (rather than caller's) binding.
Deprecated
Qfalse::new,Qnil::new,Qtrue::new,Qundef::new(use QFALSE/QNIL/QTRUE/QUNDEF).- Functions for generating an
Errorwith a specific Ruby type. E.g.Error::type_error("...")is nowError::new(exception::type_error(), "...") Binding::new. This will be removed in the future as the underlyingrb_binding_newwill not function as of Ruby 3.2.
Fixed
- Converting Ruby integers to
isize/i64/usize/u64on Windows. - Edge case where static symbol created after a dynamic symbol with the same name wouldn't be detected as static.
- Many
RArraymethods now correctly protect from exceptions (instead returningResult<_, Error>when an exception occurs).
- Functions in
-
0.1.026 Feb 2022Release notes
Open source →Added
- Support for most core classes,
String,Symbol,Integer,Float,Array,Hashand more. - Defining Rust methods as Ruby functions.
- Calling Ruby methods from Rust.
- Automatic type conversion between Rust and Ruby types.
- Conversion from Ruby exceptions to Rust Results and visa versa.
- Support for wrapping custom Rust structs as Ruby objects.
Enumeratoras a iterator.yieldto Ruby blocks.#[init]macro to mark init function to load extension withrequire.- Pre-built bindings for Ruby 2.6 - 3.1 on common platforms, build-time generated bindings otherwise.
- Support for most core classes,