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 or Binding::eval
for alternatives that
support utf-8.
Errors if s
contains a null byte, the conversion fails, or on an uncaught
Ruby exception.
Examples
assert_eq!(magnus::eval::<i64>("1 + 2").unwrap(), 3);