[][src]Function sentry::with_integration

pub fn with_integration<I, F, R>(f: F) -> R where
    F: FnOnce(&I, &Hub) -> R,
    I: Integration,
    R: Default

Looks up an integration on the current Hub.

Calls the given function with the requested integration instance when it is active on the currently active client. When multiple instances of the same integration are added, the function will be called with the first one.

Examples

use sentry::{ClientOptions, Integration};

struct MyIntegration(usize);
impl Integration for MyIntegration {}

let options = ClientOptions::default()
    .add_integration(MyIntegration(10))
    .add_integration(MyIntegration(20));

let _sentry = sentry::init(options);

let value = sentry::with_integration(|integration: &MyIntegration, _| integration.0);
assert_eq!(value, 10);