[][src]Function sentry_core::with_scope

pub fn with_scope<C, F, R>(scope_config: C, callback: F) -> R where
    C: FnOnce(&mut Scope),
    F: FnOnce() -> R, 

Temporarily pushes a scope for a single call optionally reconfiguring it.

This function takes two arguments: the first is a callback that is passed a scope and can reconfigure it. The second is callback that then executes in the context of that scope.

This is useful when extra data should be send with a single capture call for instance a different level or tags:


use sentry::protocol::Level;

    |scope| scope.set_level(Some(Level::Warning)),
    || sentry::capture_message("some message", Level::Info),

assert_eq!(captured_event.level, Level::Warning);