Function magnus::rb_sys::protect

source ·
pub fn protect<F>(func: F) -> Result<VALUE, Error>where
    F: FnOnce() -> VALUE,
Available on crate feature rb-sys-interop only.
Expand description

Calls the given closure, catching all cases of unwinding from Ruby returning them as an Error.

The most common will be exceptions, but this will also catch throw, break, next, return from a block, etc.

All functions exposed by Magnus that call Ruby in a way that may unwind already use this internally, this should only be required to wrap functions from rb-sys.