@@ -64,28 +64,29 @@ impl HubImpl {
64
64
/// The central object that can manages scopes and clients.
65
65
///
66
66
/// This can be used to capture events and manage the scope. This object is
67
- /// internally synchronized so it can be used from multiple threads if needed.
67
+ /// [`Send`][std::marker::Send] and [`Sync`][std::marker::Sync] so it can be used from
68
+ /// multiple threads if needed.
68
69
///
69
- /// Each thread has its own thread-local (`Hub::current()` ) hub, which is
70
- /// automatically derived from the main hub (`Hub::main()` ).
70
+ /// Each thread has its own thread-local ( see [ `Hub::current`] ) hub, which is
71
+ /// automatically derived from the main hub ([ `Hub::main`] ).
71
72
///
72
73
/// In most situations developers do not need to interface with the hub directly. Instead
73
74
/// toplevel convenience functions are expose that will automatically dispatch
74
- /// to the thread-local (`Hub::current()` ) hub. In some situations this might not be
75
+ /// to the thread-local ([ `Hub::current`] ) hub. In some situations this might not be
75
76
/// possible in which case it might become necessary to manually work with the
76
77
/// hub. This is for instance the case when working with async code.
77
78
///
78
- /// Hubs that are wrapped in `Arc`s can be bound to the current thread with
79
+ /// Hubs that are wrapped in [ `Arc`] s can be bound to the current thread with
79
80
/// the `run` static method.
80
81
///
81
82
/// Most common operations:
82
83
///
83
- /// * `Hub::new`: creates a brand new hub
84
- /// * `Hub::current`: returns the thread local hub
85
- /// * `Hub::with`: invoke a callback with the thread local hub
86
- /// * `Hub::with_active`: like `Hub::with` but does not invoke the callback if
84
+ /// * [ `Hub::new`] : creates a brand new hub
85
+ /// * [ `Hub::current`] : returns the thread local hub
86
+ /// * [ `Hub::with`] : invoke a callback with the thread local hub
87
+ /// * [ `Hub::with_active`] : like `Hub::with` but does not invoke the callback if
87
88
/// the client is not in a supported state or not bound
88
- /// * `Hub::new_from_top`: creates a new hub with just the top scope of another hub.
89
+ /// * [ `Hub::new_from_top`] : creates a new hub with just the top scope of another hub.
89
90
#[ derive( Debug ) ]
90
91
pub struct Hub {
91
92
#[ cfg( feature = "client" ) ]
@@ -115,31 +116,36 @@ impl Hub {
115
116
} )
116
117
}
117
118
118
- /// Returns the current hub.
119
+ /// Returns the current, thread-local hub.
119
120
///
120
- /// By default each thread gets a different thread local hub. If an
121
- /// atomically reference counted hub is available it can override this
122
- /// one here by calling `Hub::run` with a closure.
121
+ /// Invoking this will return the current thread-local hub. The first
122
+ /// time it is called on a thread, a new thread-local hub will be
123
+ /// created based on the topmost scope of the hub on the main thread as
124
+ /// returned by [`Hub::main`]. If the main thread did not yet have a
125
+ /// hub it will be created when invoking this function.
126
+ ///
127
+ /// To have control over which hub is installed as the current
128
+ /// thread-local hub, use [`Hub::run`].
123
129
///
124
130
/// This method is unavailable if the client implementation is disabled.
125
- /// When using the minimal API set use `Hub::with_active` instead.
131
+ /// When using the minimal API set use [ `Hub::with_active`] instead.
126
132
#[ cfg( feature = "client" ) ]
127
133
pub fn current ( ) -> Arc < Hub > {
128
134
Hub :: with ( Arc :: clone)
129
135
}
130
136
131
137
/// Returns the main thread's hub.
132
138
///
133
- /// This is similar to ` current` but instead of picking the current
134
- /// thread's hub it returns the main thread's hub instead.
139
+ /// This is similar to [`Hub:: current`] but instead of picking the
140
+ /// current thread's hub it returns the main thread's hub instead.
135
141
#[ cfg( feature = "client" ) ]
136
142
pub fn main ( ) -> Arc < Hub > {
137
143
PROCESS_HUB . 0 . clone ( )
138
144
}
139
145
140
146
/// Invokes the callback with the default hub.
141
147
///
142
- /// This is a slightly more efficient version than `Hub::current()` and
148
+ /// This is a slightly more efficient version than [ `Hub::current`] and
143
149
/// also unavailable in minimal mode.
144
150
#[ cfg( feature = "client" ) ]
145
151
pub fn with < F , R > ( f : F ) -> R
@@ -149,7 +155,7 @@ impl Hub {
149
155
if USE_PROCESS_HUB . with ( Cell :: get) {
150
156
f ( & PROCESS_HUB . 0 )
151
157
} else {
152
- // not on safety: this is safe because even though we change the Arc
158
+ // note on safety: this is safe because even though we change the Arc
153
159
// by temorary binding we guarantee that the original Arc stays alive.
154
160
// For more information see: run
155
161
THREAD_HUB . with ( |stack| unsafe {
@@ -159,7 +165,7 @@ impl Hub {
159
165
}
160
166
}
161
167
162
- /// Like `Hub::with` but only calls the function if a client is bound.
168
+ /// Like [ `Hub::with`] but only calls the function if a client is bound.
163
169
///
164
170
/// This is useful for integrations that want to do efficiently nothing if there is no
165
171
/// client bound. Additionally this internally ensures that the client can be safely
@@ -181,6 +187,13 @@ impl Hub {
181
187
}
182
188
183
189
/// Binds a hub to the current thread for the duration of the call.
190
+ ///
191
+ /// During the execution of `f` the given hub will be installed as the
192
+ /// thread-local hub. So any call to [`Hub::current`] during this time
193
+ /// will return the provided hub.
194
+ ///
195
+ /// Once the function is finished executing, including after it
196
+ /// paniced, the original hub is re-installed if one was present.
184
197
#[ cfg( feature = "client" ) ]
185
198
pub fn run < F : FnOnce ( ) -> R , R > ( hub : Arc < Hub > , f : F ) -> R {
186
199
let mut restore_process_hub = false ;
@@ -331,11 +344,11 @@ impl Hub {
331
344
332
345
/// End the current Release Health Session.
333
346
///
334
- /// See the global [`end_session`](crate::end_session_with)
335
- /// for more documentation.
347
+ /// See the global [`sentry::end_session`](crate::end_session) for more documentation.
336
348
pub fn end_session ( & self ) {
337
349
self . end_session_with_status ( SessionStatus :: Exited )
338
350
}
351
+
339
352
/// End the current Release Health Session with the given [`SessionStatus`].
340
353
///
341
354
/// See the global [`end_session_with_status`](crate::end_session_with_status)
0 commit comments