|
57 | 57 | //!
|
58 | 58 | //! A thread of execution is said to _enter_ a span when it begins executing,
|
59 | 59 | //! and _exit_ the span when it switches to another context. Spans may be
|
60 |
| -//! entered through the [`enter`] and [`in_scope`] methods. |
| 60 | +//! entered through the [`enter`], [`entered`], and [`in_scope`] methods. |
61 | 61 | //!
|
62 |
| -//! The `enter` method enters a span, returning a [guard] that exits the span |
| 62 | +//! The [`enter`] method enters a span, returning a [guard] that exits the span |
63 | 63 | //! when dropped
|
64 | 64 | //! ```
|
65 |
| -//! # #[macro_use] extern crate tracing; |
66 |
| -//! # use tracing::Level; |
| 65 | +//! # use tracing::{span, Level}; |
67 | 66 | //! let my_var: u64 = 5;
|
68 | 67 | //! let my_span = span!(Level::TRACE, "my_span", my_var);
|
69 | 68 | //!
|
|
86 | 85 | //! for details.
|
87 | 86 | //! </pre></div>
|
88 | 87 | //!
|
89 |
| -//! `in_scope` takes a closure or function pointer and executes it inside the |
90 |
| -//! span. |
| 88 | +//! The [`entered`] method is analogous to [`enter`], but moves the span into |
| 89 | +//! the returned guard, rather than borrowing it. This allows creating and |
| 90 | +//! entering a span in a single expression: |
| 91 | +//! |
91 | 92 | //! ```
|
92 |
| -//! # #[macro_use] extern crate tracing; |
93 |
| -//! # use tracing::Level; |
| 93 | +//! # use tracing::{span, Level}; |
| 94 | +//! // Create a span and enter it, returning a guard: |
| 95 | +//! let span = span!(Level::INFO, "my_span").entered(); |
| 96 | +//! |
| 97 | +//! // We are now inside the span! Like `enter()`, the guard returned by |
| 98 | +//! // `entered()` will exit the span when it is dropped... |
| 99 | +//! |
| 100 | +//! // ...but, it can also be exited explicitly, returning the `Span` |
| 101 | +//! // struct: |
| 102 | +//! let span = span.exit(); |
| 103 | +//! ``` |
| 104 | +//! |
| 105 | +//! Finally, [`in_scope`] takes a closure or function pointer and executes it |
| 106 | +//! inside the span: |
| 107 | +//! |
| 108 | +//! ``` |
| 109 | +//! # use tracing::{span, level}; |
94 | 110 | //! let my_var: u64 = 5;
|
95 | 111 | //! let my_span = span!(Level::TRACE, "my_span", my_var = &my_var);
|
96 | 112 | //!
|
|
309 | 325 | //! [`Subscriber`]: ../subscriber/trait.Subscriber.html
|
310 | 326 | //! [`Attributes`]: struct.Attributes.html
|
311 | 327 | //! [`enter`]: struct.Span.html#method.enter
|
| 328 | +//! [`entered`]: struct.Span.html#method.entered |
312 | 329 | //! [`in_scope`]: struct.Span.html#method.in_scope
|
313 | 330 | //! [`follows_from`]: struct.Span.html#method.follows_from
|
314 | 331 | //! [guard]: struct.Entered.html
|
|
0 commit comments