Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Avoid double-indirection through Arc<Box<T>> #380

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions sentry-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ where
let (tx, sentry_req) = sentry_request_from_http(&req, with_pii);
hub.configure_scope(|scope| {
scope.set_transaction(tx.as_deref());
scope.add_event_processor(Box::new(move |event| {
Some(process_event(event, &sentry_req))
}))
scope.add_event_processor(move |event| Some(process_event(event, &sentry_req)))
});

let fut = self.service.call(req).bind_hub(hub.clone());
Expand Down
8 changes: 4 additions & 4 deletions sentry-core/src/scope/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ impl Scope {
}

/// Add an event processor to the scope.
pub fn add_event_processor(
&mut self,
f: Box<dyn Fn(Event<'static>) -> Option<Event<'static>> + Send + Sync>,
) {
pub fn add_event_processor<F>(&mut self, f: F)
where
F: Fn(Event<'static>) -> Option<Event<'static>> + Send + Sync + 'static,
{
let _f = f;
minimal_unreachable!();
}
Expand Down
12 changes: 6 additions & 6 deletions sentry-core/src/scope/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Stack {
layers: Vec<StackLayer>,
}

pub type EventProcessor = Box<dyn Fn(Event<'static>) -> Option<Event<'static>> + Send + Sync>;
pub type EventProcessor = Arc<dyn Fn(Event<'static>) -> Option<Event<'static>> + Send + Sync>;

/// Holds contextual data for the current scope.
///
Expand Down Expand Up @@ -42,7 +42,7 @@ pub struct Scope {
pub(crate) extra: Arc<HashMap<String, Value>>,
pub(crate) tags: Arc<HashMap<String, String>>,
pub(crate) contexts: Arc<HashMap<String, Context>>,
pub(crate) event_processors: Arc<Vec<Arc<EventProcessor>>>,
pub(crate) event_processors: Arc<Vec<EventProcessor>>,
pub(crate) session: Arc<Mutex<Option<Session>>>,
}

Expand Down Expand Up @@ -215,10 +215,10 @@ impl Scope {
}

/// Add an event processor to the scope.
pub fn add_event_processor(
&mut self,
f: Box<dyn Fn(Event<'static>) -> Option<Event<'static>> + Send + Sync>,
) {
pub fn add_event_processor<F>(&mut self, f: F)
where
F: Fn(Event<'static>) -> Option<Event<'static>> + Send + Sync + 'static,
{
Arc::make_mut(&mut self.event_processors).push(Arc::new(f));
}

Expand Down
4 changes: 2 additions & 2 deletions sentry/examples/event-processors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ fn main() {
let _sentry = sentry::init(());

sentry::configure_scope(|scope| {
scope.add_event_processor(Box::new(move |mut event| {
scope.add_event_processor(|mut event| {
event.request = Some(sentry::protocol::Request {
url: Some("https://example.com/".parse().unwrap()),
method: Some("GET".into()),
..Default::default()
});
Some(event)
}));
});
});

sentry::configure_scope(|scope| {
Expand Down
4 changes: 2 additions & 2 deletions sentry/tests/test_processors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ fn test_event_processors() {
let events = sentry::test::with_captured_events(|| {
sentry::configure_scope(|scope| {
scope.set_tag("worker", "worker1");
scope.add_event_processor(Box::new(move |mut event| {
scope.add_event_processor(|mut event| {
event.user = Some(sentry::User {
email: Some("foo@example.com".into()),
..Default::default()
});
Some(event)
}));
});
});
sentry::capture_message("Hello World!", sentry::Level::Warning);
});
Expand Down