@@ -64,28 +64,29 @@ impl HubImpl {
6464/// The central object that can manages scopes and clients.
6565///
6666/// 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.
6869///
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`] ).
7172///
7273/// In most situations developers do not need to interface with the hub directly. Instead
7374/// 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
7576/// possible in which case it might become necessary to manually work with the
7677/// hub. This is for instance the case when working with async code.
7778///
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
7980/// the `run` static method.
8081///
8182/// Most common operations:
8283///
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
8788/// 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.
8990#[ derive( Debug ) ]
9091pub struct Hub {
9192 #[ cfg( feature = "client" ) ]
@@ -115,31 +116,36 @@ impl Hub {
115116 } )
116117 }
117118
118- /// Returns the current hub.
119+ /// Returns the current, thread-local hub.
119120 ///
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`].
123129 ///
124130 /// 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.
126132 #[ cfg( feature = "client" ) ]
127133 pub fn current ( ) -> Arc < Hub > {
128134 Hub :: with ( Arc :: clone)
129135 }
130136
131137 /// Returns the main thread's hub.
132138 ///
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.
135141 #[ cfg( feature = "client" ) ]
136142 pub fn main ( ) -> Arc < Hub > {
137143 PROCESS_HUB . 0 . clone ( )
138144 }
139145
140146 /// Invokes the callback with the default hub.
141147 ///
142- /// This is a slightly more efficient version than `Hub::current()` and
148+ /// This is a slightly more efficient version than [ `Hub::current`] and
143149 /// also unavailable in minimal mode.
144150 #[ cfg( feature = "client" ) ]
145151 pub fn with < F , R > ( f : F ) -> R
@@ -149,7 +155,7 @@ impl Hub {
149155 if USE_PROCESS_HUB . with ( Cell :: get) {
150156 f ( & PROCESS_HUB . 0 )
151157 } 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
153159 // by temorary binding we guarantee that the original Arc stays alive.
154160 // For more information see: run
155161 THREAD_HUB . with ( |stack| unsafe {
@@ -159,7 +165,7 @@ impl Hub {
159165 }
160166 }
161167
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.
163169 ///
164170 /// This is useful for integrations that want to do efficiently nothing if there is no
165171 /// client bound. Additionally this internally ensures that the client can be safely
@@ -181,6 +187,13 @@ impl Hub {
181187 }
182188
183189 /// 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.
184197 #[ cfg( feature = "client" ) ]
185198 pub fn run < F : FnOnce ( ) -> R , R > ( hub : Arc < Hub > , f : F ) -> R {
186199 let mut restore_process_hub = false ;
@@ -331,11 +344,11 @@ impl Hub {
331344
332345 /// End the current Release Health Session.
333346 ///
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.
336348 pub fn end_session ( & self ) {
337349 self . end_session_with_status ( SessionStatus :: Exited )
338350 }
351+
339352 /// End the current Release Health Session with the given [`SessionStatus`].
340353 ///
341354 /// See the global [`end_session_with_status`](crate::end_session_with_status)
0 commit comments