Macro rutie_serde::rutie_serde_methods [−][src]
macro_rules! rutie_serde_methods { ($itself_class : ty, $itself_name : ident, $exception_class : expr,) => { ... }; ($itself_class : ty, $itself_name : ident, $exception_class : expr, fn $method_name : ident($($arg_name : ident : $arg_type : ty), * $(,) *) -> Result < $return_type : ty, $error_type : ty > $body : block $($other_methods : tt) *) => { ... }; ($itself_class : ty, $itself_name : ident, $exception_class : expr, fn $method_name : ident($($arg_name : ident : $arg_type : ty), * $(,) *) -> $return_type : ty $body : block $($other_methods : tt) *) => { ... }; }
Expand description
A macro to define Rutie methods, which uses rutie_serde
to deserialize arguments and serialize results.
In comparison to rutie::methods!
, this macro:
- Attempts to use
rutie_serde
to deserialize into the required type for each argument. - Allows methods to return either
Result<T, E>
orT
, whereT: IntoAnyObject
andE: IntoException
. Errors are safely raised as Ruby exceptions and successful computations are serialized into Ruby objects usingrutie_serde
. - Catches any panics that occur during the execution of each method’s body, and re-raises them as a Ruby exception.
- Catches any errors that occur during
rutie_serde
deserialization/serialization and safely raises them as Ruby exceptions.
It accepts an extra exception_class
argument, which should be an expression resulting in a
rutie::Class
which is used to instantiate exceptions that are raised from panics.