Ruby::time_nano_new
,Ruby::time_timespec_new
, andTime::timespec
.- The
chrono
feature can be enabled to allow automatic conversions betweenchrono::DateTime<Utc>
andchrono::DateTime<FixedOffset>
and RubyTime
objects. typed_data::Writebarrier::writebarrier
andwritebarrier_unprotect
.
- Conversions between Ruby's
Time
and Rust'sSystemTime
now preserve nanosecond precision. - 'old-api' feature, which disables deprecation warnings for the old api is no longer a default feature.
0.7.1 - 2024-06-30
- Building docs with Ruby 3.0
0.7.0 - 2024-06-30
Thread
,Ruby::thread_create
/thread_create_from_fn
and other thread APIs.Mutex
,Ruby::mutex_new
and other mutex APIs.Fiber
,Ruby::fiber_new
/fiber_new_from_fn
and other fiber APIs (requires Ruby >= 3.1).Ruby::ary_try_from_iter
is an efficient way to create a Ruby array from a fallible Rust iterator.Ruby::hash_from_iter
andRuby::hash_try_from_iter
.RFile
implementsAsRawFd
.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
IntoIterator
forRArray
. - Implement
PartialEq
,PartialOrd
,Add
,Sub
,Mul
, andDiv
forInteger
. Time
with automatic conversion to/fromstd::time::SystemTime
.Ruby::alias_variable
.Ruby::waitpid
.RHash::lookup2
.Ruby::define_data
new for Ruby 3.3.IntoError
trait for conversion toError
, plusimpl ReturnValue for Result<T, E> where E: IntoError
to allow returning custom error types to Ruby.
- Closures/Functions used as Ruby blocks/procs take an additional first
argument of
&Ruby
.
RArray::each
. Please useary.into_iter()
orary.enumeratorize("each", ())
instead.
deprecated-send-sync-value
feature.ruby-static
feature. Instead enable the feature forrb-sys
in your Cargo.toml like so:rb-sys = { version = "*", features = ["ruby-static"] }
typed_data::Obj::get
.- The
QTRUE
,QFALSE
, andQNIL
constants. Class::undef_alloc_func
.Value::try_convert
.Binding
.gc::{mark, mark_slice, mark_movable, location}
.RStruct::as_slice
.Exception::backtrace
.
0.6.4 - 2024-05-08
- Potential deadlock in
Lazy
when accessed for the first time from multiple threads simultaneously.
0.6.3 - 2024-03-31
- Missing
IntoValueFromNative
implementation forVec
andHashMap
.
0.6.2 - 2023-09-18
- Compliation error in
bytes
feature.
0.6.1 - 2023-08-20
- Support
rb-sys
'stable-api
feature.
0.5.5 - 2023-08-20
- Support
rb-sys
'stable-api
feature. - Minimum supported Rust version is 1.60.
- Ruby 2.6 support requires enabling
rb-sys
'stable-api-compiled-fallback
feature in yourCargo.toml
like so:rb-sys = { version = "*", default-features = false, features = ["stable-api-compiled-fallback"] }
0.6.0 - 2023-07-28
value::Opaque
can be used to wrap a Ruby type to make itSend
+Sync
.value::Lazy
lazily initialises a Ruby value so it can be assigned to astatic
.value::OpaqueId
is aSend
+Sync
version ofvalue::Id
.value::LazyId
is anId
with aconst
constructor so can be assigned to astatic
and derefs toOpaqueId
.error::OpaqueError
is aSend
+Sync
version ofError
.- The
#[magnus(opaque_attr_reader)]
attribute can be set onOpaque
wrapped fields of a struct when derivingTypedData
to generate a method to return the inner value. Ruby::init
function 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_func
to remove a class' allocator function only if it is Ruby's default allocator function.Class::obj_alloc
andClass::define_alloc_func
for allocating an object without callinginitialize
, and for defining an allocator function.RTypedData::wrap_as
&typed_data::Obj<T>::wrap_as
can 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_class
returns the class of an exception as anExceptionClass
.- The
kwargs!()
macro andKwArgs
type can be used to pass keyword arguments toReprValue::funcall
, et al.
- Minimum supported Rust version in now 1.61.
- The
bytes-crate
feature has been renamed tobytes
. - The
rb-sys-interop
feature has been renamed torb-sys
. - Ruby types are no longer
Send
orSync
. These types can be madeSend
&Sync
with thedeprecated-send-sync-value
feature. This feature is meant to ease upgrading and will be removed with the next release. Value
's methods moved to theReprValue
trait.typed_data::Obj<T>
derefs toT
so nowT
's methods can be called directly ontyped_data::Obj<T>
.ReprValue
andTryConvert
added tomagnus::prelude
.typed_data::Cmp
,typed_data::Dup
andtyped_data::Inspect
traits to help with implementing#<=>
,#dup
&#clone
, and#inspect
methods for wrapped structs.- Wrapped data must be
Sync
to enablefrozen_shareable
flag. TypedData::class
andTypedData::class_for
now take a&Ruby
argument.DataTypeFunctions::mark
andDataTypeFunctions::compact
now take&gc::Marker
and&gc::Compactor
arguments respectively.- Init function marked with
#[magnus::init]
optionally takes a&Ruby
argument. - Functions bound as Ruby methods with
method!()
andfunction!()
optionally take&Ruby
as a first argument. - The value returned from
embed::init
derefs toRuby
. DataTypeBuilder::new
/DataType::builder
now take theirname
argument as a'static CStr
(see themagnus::data_type_builder!
macro to construct aDataTypeBuilder
with a'static CStr
name
).- All methods on
DataTypeBuilder
are nowconst
, soDataType
can be constructed in aconst
context and be assigned to astatic
. - The
#[wrap]
and#[derive(TypedData)]
macros now support setting the#[magnus(unsafe_generics)]
attribute to allow derivingTypedData
for types with generics. The derived implementation is not guaranteed to be correct.
typed_data::Obj::get
as it is made redundant by theDeref
implementation fortyped_data::Obj
.- The
QTRUE
,QFALSE
, andQNIL
constants. Please usevalue::qtrue()
,value::qfalse()
, andvalue::qnil()
. Class::undef_alloc_func
. Please useClass::undef_default_alloc_func
.Value::try_convert
, preferTryConvert::try_convert
orT::try_convert
.Binding
. To call methods on Ruby's binding, useReprValue::funcall
on aValue
know 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
.
- Inherent methods on
RClass
, importmagnus::Class
trait ormagnus::prelude::*
. Into<Value>
/From<T> for Value
implementations, useIntoValue
.Default
implementations forValue
,RClass
, andExceptionClass
.Error
can no longer be directly constructed, must useError::new
orError::from
/Exception::into
.RString::append
(useRString::buf_append
).Error::runtime_error
(useError::new(exception::runtime_error(), msg)
).
RFloat::from_value
now returnsNone
when value is aFlonum
.
0.5.3 - 2023-04-07
Value::as_value
method 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.2 - 2023-03-19
- Fixed compilation issue in
RBignum
on 32 bit platforms.
0.5.1 - 2023-02-18
- Documentation fixes.
0.5.0 - 2023-02-11
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_capacity
new for Ruby 3.2.RHash::bulk_insert
.Value::hash
to generate a hash key for a Ruby object.typed_data::Hash
andtyped_data::IsEql
traits to help with implementing#hash
and#eql?
methods for wrapped structs.- Lots of
RString
methods: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_get
function to get theRMatch
for the last regexp match. RMatch::nth_defined
,RMatch::nth_match
,RMatch::backref_number
,RMatch::matched
,RMatch::pre
,RMatch::post
, andRMatch::last
RBignum::is_positive
/is_negative
.new
,num
, andden
forRRational
, plusrationalize
andrationalize_with_prec
forFloat
.RComplex::new
,polar
,real
,imag
,conjugate
,abs
&arg
.- New
Numeric
trait implemented forInteger
,Float
,RRational
,RComplex
, etc. Exposes functions for applying operators to numeric types following Ruby's coercion protocol. value::Id::new
added to replacevalue::Id::from
.TypedData::class_for
can 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_public
calls a public method, returning an error for a private or protected method.error::Result<T>
is shorthand forstd::result::Result<T, Error>
.embed::setup
to perform minimal initialisation of Ruby for environments whereembed::init
doesn't work.- The
bytes-crate
feature can be enabled to allow automatic conversions betweenbytes::Bytes
and Ruby strings.
- 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_ary
for the old behaviour). r_typed_data::{DataType, DataTypeFunctions, DataTypeBuilder, TypedData}
all moved totyped_data
module,r_typed_data
module removed. This should only affectDataTypeBuilder
as it was the only one not exported at the crate root.gc::adjust_memory_usage
's argument changed toisize
, rather thani32
ori64
depending on pointer width.- The
IntoValue
trait is now used instead ofInto<Value>
for converting to Ruby types. IntoId
,IntoRString
, andIntoSymbol
are used instead ofInto<Id>
,Into<RString>
, andInto<Symbol>
.use magnus::prelude::*
will now import traits anonymously.EncodingCapable
,Module
,Class
, andObject
traits can no longer be implemented by user code.- The
wb_protected
flag is automatically set for data wrapped in a Ruby object whenmark
is not set.
RString::append
(useRString::buf_append
).Error::runtime_error
(useError::new(exception::runtime_error(), msg)
).- Implementations of
Into<Value>
(useIntoValue
).
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.
- Missing
ReprValue
implementation forRStruct
.
0.4.4 - 2022-12-24
Class::undef_alloc_func
, a function to remove a class' allocator function.
- 'wrapped' structs from
#[wrap]
and#[derive(TypedData)]
macros will not generatewarning: undefining the allocator of T_DATA class
under Ruby 3.2
0.4.3 - 2022-12-07
gc::mark_slice
was skipping the last element of the slice.
0.4.2 - 2022-11-30
- Removed errant
dbg!()
.
0.4.1 - 2022-11-29
scan_args::get_kwargs
error/segfault when leading optional args were not provided, due to trying to convert the type of the missing value.
0.4.0 - 2022-11-19
Value::funcall_with_block
.- impl
TryConvert
forException
andExceptionClass
. Class
trait (implemented forRClass
andExceptionClass
).define_error
andModule::define_error
helpers for defining an Exception Class.RTypedData::wrap
andRTypedData::get
inherent 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).
- 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_block
for closures that capture variables. Proc::new
only accepts a function pointer, useProc::from_fn
for closures that capture variables.ExceptionClass::default()
now returnsStandardError
rather thanRuntimeError
.TryConvert
now takesValue
by value (rather than a reference).
DataTypeBuilder::free_immediatly
(usefree_immediately
).free_immediatly
attribute inwrap
macro (usefree_immediately
).free_immediatly
inmagnus
attribute ofderive(TypedData)
macro (usefree_immediately
).
String::encode_utf8
, user_string.conv_enc(RbEncoding::utf8())
instead.Value::leak
, usegc::register_mark_object
instead.define_global_variable
(usedefine_variable
).
- Memory leak of the message when returning an
Error
to raise an exception. Flonum
support disabled for Ruby built with USE_FLONUM=0 (e.g. 32 bit systems).- Correct spelling of
free_immediatly
(tofree_immediately
) in theDataTypeBuilder
struct, andwrap
andderive(TypedData)
macros.
printf
-style format strings no longer interpreted in error messages when automatically raised as Ruby exceptions.
0.3.2 - 2022-05-29
- Better error output from build script when
ruby
can't be found or errors. - Fixed crash in
Proc::new
andValue::block_call
when the proc was stored and called later.
0.3.1 - 2022-05-21
- Integer overflow in Ruby Float to f64 conversion
0.3.0 - 2022-05-18
RString::new_shared
andRString::new_frozen
.encoding
module, includingencoding::Index
andRbEncoding
types.RString::enc_coderange
and related methods.RString::codepoints
andRString::char_bytes
iterators 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
. RHash
gains the methodsdelete
andclear
.require
,current_receiver
,call_super
, anddefine_global_const
functions.Object::singleton_class
andObject::extend_object
.Proc::new
,Proc::arity
, andProc::is_lambda
.superclass
andname
methods forRClass
.scan_args::check_arity
.- Methods for
Module
:include_module
,prepend_module
,const_set
,ancestors
,define_attr
, anddefine_alias
. rb-sys-interop
feature to use low level bindings from rb-sys, andrb_sys
module 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::check
andId::check
to check if a symbol exists.
RArray::cat
,RArray::from_slice
, andgc::mark_slice
will 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::location
will accept any Ruby type as an argument. BoxValue
can 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::foreach
will now be automatically converted fromValue
to Rust types. Module::define_method
,Module::define_private_method
,Module::define_protected_method
,RModule::define_singleton_method
, andObject::define_singleton_method
all returnResult<(), Error>
rather than()
as they may fail in the unusual case that the receiver is frozen.
String::encode_utf8
, user_string.conv_enc(RbEncoding::utf8())
instead.Value::leak
, usegc::register_mark_object
instead.define_global_variable
(usedefine_variable
) to better match Ruby C API naming.Exception::backtrace
, useex.funcall("backtrace", ())
instead.
error::protect
removed as it should not be needed when using Magnus. For use with rb-sys enable therb-sys-interop
feature and usemagnus::rb_sys::protect
.Qfalse::new
,Qnil::new
,Qtrue::new
,Qundef::new
(use QFALSE/QNIL/QTRUE/QUNDEF).- Functions for generating an
Error
with a specific Ruby type. E.g.Error::type_error("...")
, useError::new(exception::type_error(), "...")
.
- creating a
StaticSymbol
from a&str
with characters outside the ASCII range. - panicking in any of the functions of
DataTypeFunctions
will abort the process to avoid undefined behaviour. - panicking in the closure passed to
RHash::foreach
won't result in undefined behaviour.
0.2.1 - 2022-04-03
- Fixed compilation error in
method!
andfunction!
macros with arity argument of 5.
0.2.0 - 2022-03-31
- Functions in
class
,module
, anderror
modules 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::new
andModule::new
for creating anonymous classes/modules.r_string!
macro to create Ruby string from astr
literal.Value::equal
andValue::eql
for object equality.Value::respond_to
andValue::check_funcall
for conditionally calling Ruby methods only when they are defined.scan_args
andget_kwargs
for complex argument parsing.
Qundef::to_value
now markedunsafe
.RArray::cat
,RArray::push
,RArray::unshift
, andRArray::store
now returnResult<(), Error>
.eval!
macro uses anonymous (rather than caller's) binding.
Qfalse::new
,Qnil::new
,Qtrue::new
,Qundef::new
(use QFALSE/QNIL/QTRUE/QUNDEF).- Functions for generating an
Error
with 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_new
will not function as of Ruby 3.2.
- Converting Ruby integers to
isize
/i64
/usize
/u64
on Windows. - Edge case where static symbol created after a dynamic symbol with the same name wouldn't be detected as static.
- Many
RArray
methods now correctly protect from exceptions (instead returningResult<_, Error>
when an exception occurs).
0.1.0 - 2022-02-25
- Support for most core classes,
String
,Symbol
,Integer
,Float
,Array
,Hash
and 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.
Enumerator
as a iterator.yield
to 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.