Open abinoam opened 4 years ago
I really like this idea and I think the code sample you've provided a beautiful in illustrating how we can improve.
Does the word typed
accurately describe what is being done here? The reason this question comes to mind is everything in Rust is already typed, so it doesn't appear to be named for the problem it's solving. It's a form of destructuring or safe unwrapping. Something like pure_methods!
might be nice, or even better ruby_methods!
given the context is being able to raise the error within the Ruby VM.
My preference leans towards ruby_methods!
, but I'm open to persuasion on this one.
I liked ruby_methods!
.
Bear in mind that I'm Brazilian and I'm far from being a good english language reference. So, please double check my naming suggestion (in english).
If I use the
methods!
macro I keep repeating the unwrapping of the args and treating them with a raise ArgumentError at the VM so it doesn't panic at the Rust side and it gives the opportunity to the Ruby code to treat the error. In my small project I've created a trait to easy this task.And I use it like this:
This gets tedious. Is it possible to create a sister macro called
typed_methods!
where this tedious work is done automatically?Se we would have 3 sister macros:
unsafe_methods!
that doesn't wrap argsmethods!
that wraps args and it gives the task for you to handletyped_methods
(or other name) that handle the checking and automatically rb_raise for you so you have a clean code with the guarantee of having args with correct type.Just an initial idea.