Skip to content

Commit bff4693

Browse files
committed
chore: rearrange switch guard function
1 parent f537a94 commit bff4693

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

sentry-core/src/hub.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use std::sync::{Arc, RwLock};
66

7-
use crate::hub_impl::SwitchGuard;
7+
// use crate::hub_impl::SwitchGuard;
88
use crate::protocol::{Event, Level, SessionStatus};
99
use crate::types::Uuid;
1010
use crate::{Integration, IntoBreadcrumbs, Scope, ScopeGuard};
@@ -243,10 +243,4 @@ impl Hub {
243243
})
244244
}}
245245
}
246-
247-
#[inline(always)]
248-
/// Consumes self to create switch guard, that can be used to modify current hub in thread local storage
249-
pub fn into_switch_guard(self: Arc<Hub>) -> SwitchGuard {
250-
crate::hub_impl::SwitchGuard::new(self)
251-
}
252246
}

sentry-core/src/hub_impl.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ thread_local! {
2121
);
2222
}
2323

24-
///Hub switch guard
25-
///
26-
///Used to temporarily swap active hub in thread local storage.
24+
/// A Hub switch guard used to temporarily swap
25+
/// active hub in thread local storage.
2726
pub struct SwitchGuard {
2827
inner: Option<(Arc<Hub>, bool)>,
2928
}
3029

3130
impl SwitchGuard {
32-
pub(crate) fn new(mut hub: Arc<Hub>) -> Self {
31+
/// Swaps the current thread's Hub by the one provided
32+
/// and returns a guard that, when dropped, replaces it
33+
/// to the previous one.
34+
pub fn new(mut hub: Arc<Hub>) -> Self {
3335
let inner = THREAD_HUB.with(|(thread_hub, is_process_hub)| {
3436
// SAFETY: `thread_hub` will always be a valid thread local hub,
3537
// by definition not shared between threads.

sentry-core/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ pub use crate::clientoptions::{BeforeCallback, ClientOptions, SessionMode};
130130
pub use crate::error::{capture_error, event_from_error, parse_type_from_debug};
131131
pub use crate::futures::{SentryFuture, SentryFutureExt};
132132
pub use crate::hub::Hub;
133-
pub use crate::hub_impl::SwitchGuard as HubSwitchGuard;
134133
pub use crate::integration::Integration;
135134
pub use crate::intodsn::IntoDsn;
136135
pub use crate::performance::*;
@@ -150,8 +149,9 @@ pub mod metrics;
150149
mod session;
151150
#[cfg(all(feature = "client", feature = "metrics"))]
152151
mod units;
152+
153153
#[cfg(feature = "client")]
154-
pub use crate::client::Client;
154+
pub use crate::{client::Client, hub_impl::SwitchGuard as HubSwitchGuard};
155155

156156
// test utilities
157157
#[cfg(feature = "test")]

sentry-tracing/src/layer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ where
292292

293293
let mut extensions = span.extensions_mut();
294294
if let Some(data) = extensions.get_mut::<SentrySpanData>() {
295-
data.hub_switch_guard = Some(data.hub.clone().into_switch_guard());
295+
data.hub_switch_guard = Some(sentry_core::HubSwitchGuard::new(data.hub.clone()));
296296
data.hub.configure_scope(|scope| {
297297
scope.set_span(Some(data.sentry_span.clone()));
298298
})
@@ -311,7 +311,7 @@ where
311311
data.hub.configure_scope(|scope| {
312312
scope.set_span(data.parent_sentry_span.clone());
313313
});
314-
data.hub_switch_guard = None;
314+
data.hub_switch_guard.take();
315315
}
316316
}
317317

0 commit comments

Comments
 (0)