pub fn with_context<F, O>(new: MacroContext, f: F) -> O
where
    F: FnOnce() -> O,
{
    let old = MACRO_CONTEXT.with(|ctx| {
        let mut ctx = ctx
            .try_borrow_mut()
            .expect("expected exclusive access to macro context");

        ctx.replace(new)
    });

    let _guard = Guard(old);
    return f();

    struct Guard(Option<MacroContext>);

    impl Drop for Guard {
        fn drop(&mut self) {
            let old = self.0.take();

            MACRO_CONTEXT.with(|ctx| {
                let mut ctx = ctx
                    .try_borrow_mut()
                    .expect("expected exclusive access to macro context");

                *ctx = old;
            });
        }
    }
}
/// Install the given context and call the provided function with the installed
/// context.
///
/// # Panics
///
/// This will panic if called while the current context is in use.
///
/// # Examples
///
/// ```rust
/// use rune::macros::{with_context, MacroContext};
/// let ctx = MacroContext::empty();
///
/// with_context(ctx, || {
///     rune::quote!(hello self);
/// });
/// ```
Install the given context and call the provided function with the installed
context.
Install the given context and call the provided function with the installed context .
pub fn with_context<F, O>(new: MacroContext, f: F) -> O
where
    F: FnOnce() -> O,
{
    let old = MACRO_CONTEXT.with(|ctx| {
        let mut ctx = ctx
            .try_borrow_mut()
            .expect("expected exclusive access to macro context");
        ctx.replace(new)
    });
    let _guard = Guard(old);
    return f();
    struct Guard(Option<MacroContext>);
    impl Drop for Guard {
        fn drop(&mut self) {
            let old = self.0.take();
            MACRO_CONTEXT.with(|ctx| {
                let mut ctx = ctx
                    .try_borrow_mut()
                    .expect("expected exclusive access to macro context");
                *ctx = old;
            });
        }
    }
}
pub fn with_context < F , O > ( new : MacroContext , f : F ) -> O where F : FnOnce ( ) -> O , { let old = MACRO_CONTEXT . with ( | ctx | { let mut ctx = ctx . try_borrow_mut ( ) . expect ( " " ) ; ctx . replace ( new ) } ) ; let _guard = Guard ( old ) ; return f ( ) ; struct Guard ( Option < MacroContext > ) ; impl Drop for Guard { fn drop ( & mut self ) { let old = self . 0 . take ( ) ; MACRO_CONTEXT . with ( | ctx | { let mut ctx = ctx . try_borrow_mut ( ) . expect ( " " ) ; * ctx = old ; } ) ; } } }
Install the given context and call the provided function with the installed
context.
Install the given context and call the provided function with the installed context .
new
MacroContext
f
F
new
MacroContext
f
F
panics
This will panic if called while the current context is in use.
This will panic if called while the current context is in use .
examples
```rust
use rune::macros::{with_context, MacroContext};
let ctx = MacroContext::empty().


` ` ` rust use rune :: macros :: { with_context MacroContext } ; let ctx = MacroContext :: empty () .