Function magnus::eval

source ·
pub fn eval<T>(s: &str) -> Result<T, Error>
where T: TryConvert,
Expand description

Evaluate a string of Ruby code, converting the result to a T.

Ruby will use the ‘ASCII-8BIT’ (aka binary) encoding for any Ruby string literals in the passed string of Ruby code. See the eval macro for an alternative that supports utf-8.

Errors if s contains a null byte, the conversion fails, or on an uncaught Ruby exception.

§Panics

Panics if called from a non-Ruby thread. See Ruby::eval for the non-panicking version.

§Examples

assert_eq!(magnus::eval::<i64>("1 + 2").unwrap(), 3);