-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstruct.Span.html
532 lines (444 loc) · 90.5 KB
/
struct.Span.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A handle representing a span, with the capability to enter the span if it exists."><title>Span in tracing - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-46132b98.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="tracing" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0 (4d91de4e4 2025-02-17)" data-channel="1.85.0" data-search-js="search-75f5ac3e.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../tracing/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../tracing/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></a><h2><a href="../tracing/index.html">tracing</a><span class="version">0.1.41</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Span</a></h2><h3><a href="#fields">Fields</a></h3><ul class="block structfield"><li><a href="#structfield.inner" title="inner">inner</a></li><li><a href="#structfield.meta" title="meta">meta</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.child_of" title="child_of">child_of</a></li><li><a href="#method.current" title="current">current</a></li><li><a href="#method.do_enter" title="do_enter">do_enter</a></li><li><a href="#method.do_exit" title="do_exit">do_exit</a></li><li><a href="#method.enter" title="enter">enter</a></li><li><a href="#method.entered" title="entered">entered</a></li><li><a href="#method.field" title="field">field</a></li><li><a href="#method.follows_from" title="follows_from">follows_from</a></li><li><a href="#method.has_field" title="has_field">has_field</a></li><li><a href="#method.id" title="id">id</a></li><li><a href="#method.in_scope" title="in_scope">in_scope</a></li><li><a href="#method.is_disabled" title="is_disabled">is_disabled</a></li><li><a href="#method.is_none" title="is_none">is_none</a></li><li><a href="#method.log" title="log">log</a></li><li><a href="#method.make_with" title="make_with">make_with</a></li><li><a href="#method.metadata" title="metadata">metadata</a></li><li><a href="#method.new" title="new">new</a></li><li><a href="#method.new_disabled" title="new_disabled">new_disabled</a></li><li><a href="#method.new_root" title="new_root">new_root</a></li><li><a href="#method.none" title="none">none</a></li><li><a href="#method.or_current" title="or_current">or_current</a></li><li><a href="#method.record" title="record">record</a></li><li><a href="#method.record_all" title="record_all">record_all</a></li><li><a href="#method.with_subscriber" title="with_subscriber">with_subscriber</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Clone-for-Span" title="Clone">Clone</a></li><li><a href="#impl-Debug-for-Span" title="Debug">Debug</a></li><li><a href="#impl-Drop-for-Span" title="Drop">Drop</a></li><li><a href="#impl-From%3C%26Span%3E-for-Option%3C%26Id%3E" title="From<&'a Span>">From<&'a Span></a></li><li><a href="#impl-From%3C%26Span%3E-for-Option%3CId%3E" title="From<&'a Span>">From<&'a Span></a></li><li><a href="#impl-From%3CSpan%3E-for-Option%3CId%3E" title="From<Span>">From<Span></a></li><li><a href="#impl-Hash-for-Span" title="Hash">Hash</a></li><li><a href="#impl-PartialEq-for-Span" title="PartialEq">PartialEq</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-RefUnwindSafe-for-Span" title="!RefUnwindSafe">!RefUnwindSafe</a></li><li><a href="#impl-UnwindSafe-for-Span" title="!UnwindSafe">!UnwindSafe</a></li><li><a href="#impl-Freeze-for-Span" title="Freeze">Freeze</a></li><li><a href="#impl-Send-for-Span" title="Send">Send</a></li><li><a href="#impl-Sync-for-Span" title="Sync">Sync</a></li><li><a href="#impl-Unpin-for-Span" title="Unpin">Unpin</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow<T>">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut<T>">BorrowMut<T></a></li><li><a href="#impl-CloneToUninit-for-T" title="CloneToUninit">CloneToUninit</a></li><li><a href="#impl-From%3CT%3E-for-T" title="From<T>">From<T></a></li><li><a href="#impl-Instrument-for-T" title="Instrument">Instrument</a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into<U>">Into<U></a></li><li><a href="#impl-ToOwned-for-T" title="ToOwned">ToOwned</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom<U>">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto<U>">TryInto<U></a></li><li><a href="#impl-WithSubscriber-for-T" title="WithSubscriber">WithSubscriber</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate tracing</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">tracing</a></span><h1>Struct <span class="struct">Span</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/tracing/span.rs.html#348-358">Source</a> </span></div><pre class="rust item-decl"><code>pub struct Span {
inner: <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><<a class="struct" href="span/struct.Inner.html" title="struct tracing::span::Inner">Inner</a>>,
meta: <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><&'static <a class="struct" href="struct.Metadata.html" title="struct tracing::Metadata">Metadata</a><'static>>,
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A handle representing a span, with the capability to enter the span if it
exists.</p>
<p>If the span was rejected by the current <code>Subscriber</code>’s filter, entering the
span will silently do nothing. Thus, the handle can be used in the same
manner regardless of whether or not the trace is currently being collected.</p>
</div></details><h2 id="fields" class="fields section-header">Fields<a href="#fields" class="anchor">§</a></h2><span id="structfield.inner" class="structfield section-header"><a href="#structfield.inner" class="anchor field">§</a><code>inner: <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><<a class="struct" href="span/struct.Inner.html" title="struct tracing::span::Inner">Inner</a>></code></span><div class="docblock"><p>A handle used to enter the span when it is not executing.</p>
<p>If this is <code>None</code>, then the span has either closed or was never enabled.</p>
</div><span id="structfield.meta" class="structfield section-header"><a href="#structfield.meta" class="anchor field">§</a><code>meta: <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><&'static <a class="struct" href="struct.Metadata.html" title="struct tracing::Metadata">Metadata</a><'static>></code></span><div class="docblock"><p>Metadata describing the span.</p>
<p>This might be <code>Some</code> even if <code>inner</code> is <code>None</code>, in the case that the
span is disabled but the metadata is needed for <code>log</code> support.</p>
</div><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Span" class="impl"><a class="src rightside" href="../src/tracing/span.rs.html#422-1367">Source</a><a href="#impl-Span" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#436-438">Source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>(meta: &'static <a class="struct" href="struct.Metadata.html" title="struct tracing::Metadata">Metadata</a><'static>, values: &<a class="struct" href="field/struct.ValueSet.html" title="struct tracing::field::ValueSet">ValueSet</a><'_>) -> <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h4></section></summary><div class="docblock"><p>Constructs a new <code>Span</code> with the given <a href="struct.Metadata.html" title="struct tracing::Metadata">metadata</a> and set of
<a href="field/struct.ValueSet.html" title="struct tracing::field::ValueSet">field values</a>.</p>
<p>The new span will be constructed by the currently-active <a href="trait.Subscriber.html" title="trait tracing::Subscriber"><code>Subscriber</code></a>,
with the current span as its parent (if one exists).</p>
<p>After the span is constructed, <a href="field/struct.ValueSet.html" title="struct tracing::field::ValueSet">field values</a> and/or <a href="struct.Span.html#method.follows_from" title="method tracing::Span::follows_from"><code>follows_from</code></a>
annotations may be added to it.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.new_root" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#460-462">Source</a><h4 class="code-header">pub fn <a href="#method.new_root" class="fn">new_root</a>(meta: &'static <a class="struct" href="struct.Metadata.html" title="struct tracing::Metadata">Metadata</a><'static>, values: &<a class="struct" href="field/struct.ValueSet.html" title="struct tracing::field::ValueSet">ValueSet</a><'_>) -> <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h4></section></summary><div class="docblock"><p>Constructs a new <code>Span</code> as the root of its own trace tree, with the
given <a href="struct.Metadata.html" title="struct tracing::Metadata">metadata</a> and set of <a href="field/struct.ValueSet.html" title="struct tracing::field::ValueSet">field values</a>.</p>
<p>After the span is constructed, <a href="field/struct.ValueSet.html" title="struct tracing::field::ValueSet">field values</a> and/or <a href="struct.Span.html#method.follows_from" title="method tracing::Span::follows_from"><code>follows_from</code></a>
annotations may be added to it.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.child_of" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#484-493">Source</a><h4 class="code-header">pub fn <a href="#method.child_of" class="fn">child_of</a>(
parent: impl <a class="trait" href="stdlib/convert/trait.Into.html" title="trait tracing::stdlib::convert::Into">Into</a><<a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><<a class="struct" href="span/struct.Id.html" title="struct tracing::span::Id">Id</a>>>,
meta: &'static <a class="struct" href="struct.Metadata.html" title="struct tracing::Metadata">Metadata</a><'static>,
values: &<a class="struct" href="field/struct.ValueSet.html" title="struct tracing::field::ValueSet">ValueSet</a><'_>,
) -> <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h4></section></summary><div class="docblock"><p>Constructs a new <code>Span</code> as child of the given parent span, with the
given <a href="struct.Metadata.html" title="struct tracing::Metadata">metadata</a> and set of <a href="field/struct.ValueSet.html" title="struct tracing::field::ValueSet">field values</a>.</p>
<p>After the span is constructed, <a href="field/struct.ValueSet.html" title="struct tracing::field::ValueSet">field values</a> and/or <a href="struct.Span.html#method.follows_from" title="method tracing::Span::follows_from"><code>follows_from</code></a>
annotations may be added to it.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.new_disabled" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#519-524">Source</a><h4 class="code-header">pub fn <a href="#method.new_disabled" class="fn">new_disabled</a>(meta: &'static <a class="struct" href="struct.Metadata.html" title="struct tracing::Metadata">Metadata</a><'static>) -> <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h4></section></summary><div class="docblock"><p>Constructs a new disabled span with the given <code>Metadata</code>.</p>
<p>This should be used when a span is constructed from a known callsite,
but the subscriber indicates that it is disabled.</p>
<p>Entering, exiting, and recording values on this span will not notify the
<code>Subscriber</code> but <em>may</em> record log messages if the <code>log</code> feature flag is
enabled.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.none" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#533-538">Source</a><h4 class="code-header">pub const fn <a href="#method.none" class="fn">none</a>() -> <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h4></section></summary><div class="docblock"><p>Constructs a new span that is <em>completely disabled</em>.</p>
<p>This can be used rather than <code>Option<Span></code> to represent cases where a
span is not present.</p>
<p>Entering, exiting, and recording values on this span will do nothing.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.current" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#549-561">Source</a><h4 class="code-header">pub fn <a href="#method.current" class="fn">current</a>() -> <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h4></section></summary><div class="docblock"><p>Returns a handle to the span <a href="trait.Subscriber.html#method.current_span" title="method tracing::Subscriber::current_span">considered by the <code>Subscriber</code></a> to be the
current span.</p>
<p>If the subscriber indicates that it does not track the current span, or
that the thread from which this function is called is not currently
inside a span, the returned span will be disabled.</p>
</div></details><section id="method.make_with" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#563-592">Source</a><h4 class="code-header">fn <a href="#method.make_with" class="fn">make_with</a>(
meta: &'static <a class="struct" href="struct.Metadata.html" title="struct tracing::Metadata">Metadata</a><'static>,
new_span: <a class="struct" href="span/struct.Attributes.html" title="struct tracing::span::Attributes">Attributes</a><'_>,
dispatch: &<a class="struct" href="struct.Dispatch.html" title="struct tracing::Dispatch">Dispatch</a>,
) -> <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h4></section><details class="toggle method-toggle" open><summary><section id="method.enter" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#785-788">Source</a><h4 class="code-header">pub fn <a href="#method.enter" class="fn">enter</a>(&self) -> <a class="struct" href="span/struct.Entered.html" title="struct tracing::span::Entered">Entered</a><'_></h4></section></summary><div class="docblock"><p>Enters this span, returning a guard that will exit the span when dropped.</p>
<p>If this span is enabled by the current subscriber, then this function will
call <a href="trait.Subscriber.html#tymethod.enter" title="method tracing::Subscriber::enter"><code>Subscriber::enter</code></a> with the span’s <a href="span/struct.Id.html" title="struct tracing::span::Id"><code>Id</code></a>, and dropping the guard
will call <a href="trait.Subscriber.html#tymethod.exit" title="method tracing::Subscriber::exit"><code>Subscriber::exit</code></a>. If the span is disabled, this does
nothing.</p>
<h5 id="in-asynchronous-code"><a class="doc-anchor" href="#in-asynchronous-code">§</a>In Asynchronous Code</h5>
<p><strong>Warning</strong>: in asynchronous code that uses <a href="https://rust-lang.github.io/async-book/01_getting_started/04_async_await_primer.html">async/await syntax</a>,
<code>Span::enter</code> should be used very carefully or avoided entirely. Holding
the drop guard returned by <code>Span::enter</code> across <code>.await</code> points will
result in incorrect traces. For example,</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>my_async_function() {
<span class="kw">let </span>span = <span class="macro">info_span!</span>(<span class="string">"my_async_function"</span>);
<span class="comment">// WARNING: This span will remain entered until this
// guard is dropped...
</span><span class="kw">let </span>_enter = span.enter();
<span class="comment">// ...but the `await` keyword may yield, causing the
// runtime to switch to another task, while remaining in
// this span!
</span>some_other_async_function().<span class="kw">await
</span><span class="comment">// ...
</span>}</code></pre></div>
<p>The drop guard returned by <code>Span::enter</code> exits the span when it is
dropped. When an async function or async block yields at an <code>.await</code>
point, the current scope is <em>exited</em>, but values in that scope are
<strong>not</strong> dropped (because the async block will eventually resume
execution from that await point). This means that <em>another</em> task will
begin executing while <em>remaining</em> in the entered span. This results in
an incorrect trace.</p>
<p>Instead of using <code>Span::enter</code> in asynchronous code, prefer the
following:</p>
<ul>
<li>
<p>To enter a span for a synchronous section of code within an async
block or function, prefer <a href="struct.Span.html#method.in_scope" title="method tracing::Span::in_scope"><code>Span::in_scope</code></a>. Since <code>in_scope</code> takes a
synchronous closure and exits the span when the closure returns, the
span will always be exited before the next await point. For example:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>my_async_function() {
<span class="kw">let </span>span = <span class="macro">info_span!</span>(<span class="string">"my_async_function"</span>);
<span class="kw">let </span>some_value = span.in_scope(|| {
<span class="comment">// run some synchronous code inside the span...
</span>});
<span class="comment">// This is okay! The span has already been exited before we reach
// the await point.
</span>some_other_async_function(some_value).<span class="kw">await</span>;
<span class="comment">// ...
</span>}</code></pre></div>
</li>
<li>
<p>For instrumenting asynchronous code, <code>tracing</code> provides the
<a href="trait.Instrument.html" title="trait tracing::Instrument"><code>Future::instrument</code> combinator</a> for
attaching a span to a future (async function or block). This will
enter the span <em>every</em> time the future is polled, and exit it whenever
the future yields.</p>
<p><code>Instrument</code> can be used with an async block inside an async function:</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::Instrument;
<span class="kw">async fn </span>my_async_function() {
<span class="kw">let </span>span = <span class="macro">info_span!</span>(<span class="string">"my_async_function"</span>);
<span class="kw">async move </span>{
<span class="comment">// This is correct! If we yield here, the span will be exited,
// and re-entered when we resume.
</span>some_other_async_function().<span class="kw">await</span>;
<span class="comment">//more asynchronous code inside the span...
</span>}
<span class="comment">// instrument the async block with the span...
</span>.instrument(span)
<span class="comment">// ...and await it.
</span>.<span class="kw">await
</span>}</code></pre></div>
<p>It can also be used to instrument calls to async functions at the
callsite:</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::Instrument;
<span class="kw">async fn </span>my_async_function() {
<span class="kw">let </span>some_value = some_other_async_function()
.instrument(<span class="macro">debug_span!</span>(<span class="string">"some_other_async_function"</span>))
.<span class="kw">await</span>;
<span class="comment">// ...
</span>}</code></pre></div>
</li>
<li>
<p>The <a href="macro@crate::instrument"><code>#[instrument]</code> attribute macro</a> can automatically generate
correct code when used on an async function:</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="attr">#[tracing::instrument(level = <span class="string">"info"</span>)]
</span><span class="kw">async fn </span>my_async_function() {
<span class="comment">// This is correct! If we yield here, the span will be exited,
// and re-entered when we resume.
</span>some_other_async_function().<span class="kw">await</span>;
<span class="comment">// ...
</span>}</code></pre></div>
</li>
</ul>
<h5 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>span = <span class="macro">span!</span>(Level::INFO, <span class="string">"my_span"</span>);
<span class="kw">let </span>guard = span.enter();
<span class="comment">// code here is within the span
</span>drop(guard);
<span class="comment">// code here is no longer within the span
</span></code></pre></div>
<p>Guards need not be explicitly dropped:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>my_function() -> String {
<span class="comment">// enter a span for the duration of this function.
</span><span class="kw">let </span>span = <span class="macro">trace_span!</span>(<span class="string">"my_function"</span>);
<span class="kw">let </span>_enter = span.enter();
<span class="comment">// anything happening in functions we call is still inside the span...
</span>my_other_function();
<span class="comment">// returning from the function drops the guard, exiting the span.
</span><span class="kw">return </span><span class="string">"Hello world"</span>.to_owned();
}
<span class="kw">fn </span>my_other_function() {
<span class="comment">// ...
</span>}</code></pre></div>
<p>Sub-scopes may be created to limit the duration for which the span is
entered:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>span = <span class="macro">info_span!</span>(<span class="string">"my_great_span"</span>);
{
<span class="kw">let </span>_enter = span.enter();
<span class="comment">// this event occurs inside the span.
</span><span class="macro">info!</span>(<span class="string">"i'm in the span!"</span>);
<span class="comment">// exiting the scope drops the guard, exiting the span.
</span>}
<span class="comment">// this event is not inside the span.
</span><span class="macro">info!</span>(<span class="string">"i'm outside the span!"</span>)</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.entered" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#896-902">Source</a><h4 class="code-header">pub fn <a href="#method.entered" class="fn">entered</a>(self) -> <a class="struct" href="span/struct.EnteredSpan.html" title="struct tracing::span::EnteredSpan">EnteredSpan</a></h4></section></summary><div class="docblock"><p>Enters this span, consuming it and returning a <a href="span/struct.EnteredSpan.html" title="struct tracing::span::EnteredSpan">guard</a>
that will exit the span when dropped.</p>
<pre class="compile_fail" style="white-space:normal;font:inherit;">
<strong>Warning</strong>: In asynchronous code that uses async/await syntax,
<code>Span::entered</code> may produce incorrect traces if the returned drop
guard is held across an await point. See <a href="#in-asynchronous-code">the
<code>Span::enter</code> documentation</a> for details.
</pre>
<p>If this span is enabled by the current subscriber, then this function will
call <a href="trait.Subscriber.html#tymethod.enter" title="method tracing::Subscriber::enter"><code>Subscriber::enter</code></a> with the span’s <a href="span/struct.Id.html" title="struct tracing::span::Id"><code>Id</code></a>, and dropping the guard
will call <a href="trait.Subscriber.html#tymethod.exit" title="method tracing::Subscriber::exit"><code>Subscriber::exit</code></a>. If the span is disabled, this does
nothing.</p>
<p>This is similar to the <a href="struct.Span.html#method.enter" title="method tracing::Span::enter"><code>Span::enter</code></a> method, except that it moves the
span by value into the returned guard, rather than borrowing it.
Therefore, this method can be used to create and enter a span in a
single expression, without requiring a <code>let</code>-binding. For example:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>_span = <span class="macro">info_span!</span>(<span class="string">"something_interesting"</span>).entered();</code></pre></div>
<p>rather than:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>span = <span class="macro">info_span!</span>(<span class="string">"something_interesting"</span>);
<span class="kw">let </span>_e = span.enter();</code></pre></div>
<p>Furthermore, <code>entered</code> may be used when the span must be stored in some
other struct or be passed to a function while remaining entered.</p>
<pre class="ignore" style="white-space:normal;font:inherit;">
<strong>Note</strong>: The returned <a href="../struct.EnteredSpan.html">
<code>EnteredSpan</code></a> guard does not implement <code>Send</code>.
Dropping the guard will exit <em>this</em> span, and if the guard is sent
to another thread and dropped there, that thread may never have entered
this span. Thus, <code>EnteredSpan</code>s should not be sent between threads.
</pre>
<h5 id="examples-1"><a class="doc-anchor" href="#examples-1">§</a>Examples</h5>
<p>The returned guard can be <a href="span/struct.EnteredSpan.html#method.exit" title="method tracing::span::EnteredSpan::exit">explicitly exited</a>,
returning the un-entered span:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>span = <span class="macro">span!</span>(Level::INFO, <span class="string">"doing_something"</span>).entered();
<span class="comment">// code here is within the span
// explicitly exit the span, returning it
</span><span class="kw">let </span>span = span.exit();
<span class="comment">// code here is no longer within the span
// enter the span again
</span><span class="kw">let </span>span = span.entered();
<span class="comment">// now we are inside the span once again</span></code></pre></div>
<p>Guards need not be explicitly dropped:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>my_function() -> String {
<span class="comment">// enter a span for the duration of this function.
</span><span class="kw">let </span>span = <span class="macro">trace_span!</span>(<span class="string">"my_function"</span>).entered();
<span class="comment">// anything happening in functions we call is still inside the span...
</span>my_other_function();
<span class="comment">// returning from the function drops the guard, exiting the span.
</span><span class="kw">return </span><span class="string">"Hello world"</span>.to_owned();
}
<span class="kw">fn </span>my_other_function() {
<span class="comment">// ...
</span>}</code></pre></div>
<p>Since the <a href="span/struct.EnteredSpan.html" title="struct tracing::span::EnteredSpan"><code>EnteredSpan</code></a> guard can dereference to the <a href="struct.Span.html" title="struct tracing::Span"><code>Span</code></a> itself,
the span may still be accessed while entered. For example:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::field;
<span class="comment">// create the span with an empty field, and enter it.
</span><span class="kw">let </span>span = <span class="macro">info_span!</span>(<span class="string">"my_span"</span>, some_field = field::Empty).entered();
<span class="comment">// we can still record a value for the field while the span is entered.
</span>span.record(<span class="string">"some_field"</span>, <span class="kw-2">&</span><span class="string">"hello world!"</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.or_current" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1027-1032">Source</a><h4 class="code-header">pub fn <a href="#method.or_current" class="fn">or_current</a>(self) -> Self</h4></section></summary><div class="docblock"><p>Returns this span, if it was <a href="trait.Subscriber.html#tymethod.enabled" title="method tracing::Subscriber::enabled">enabled</a> by the current <a href="trait.Subscriber.html" title="trait tracing::Subscriber"><code>Subscriber</code></a>, or
the <a href="struct.Span.html#method.current" title="associated function tracing::Span::current">current span</a> (whose lexical distance may be further than expected),
if this span <a href="struct.Span.html#method.is_disabled" title="method tracing::Span::is_disabled">is disabled</a>.</p>
<p>This method can be useful when propagating spans to spawned threads or
<a href="stdlib/task/index.html" title="mod tracing::stdlib::task">async tasks</a>. Consider the following:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>_parent_span = <span class="macro">tracing::info_span!</span>(<span class="string">"parent"</span>).entered();
<span class="comment">// ...
</span><span class="kw">let </span>child_span = <span class="macro">tracing::debug_span!</span>(<span class="string">"child"</span>);
std::thread::spawn(<span class="kw">move </span>|| {
<span class="kw">let </span>_entered = child_span.entered();
<span class="macro">tracing::info!</span>(<span class="string">"spawned a thread!"</span>);
<span class="comment">// ...
</span>});</code></pre></div>
<p>If the current <a href="trait.Subscriber.html" title="trait tracing::Subscriber"><code>Subscriber</code></a> enables the <a href="struct.Level.html#associatedconstant.DEBUG" title="associated constant tracing::Level::DEBUG"><code>DEBUG</code></a> level, then both
the “parent” and “child” spans will be enabled. Thus, when the “spawaned
a thread!” event occurs, it will be inside of the “child” span. Because
“parent” is the parent of “child”, the event will <em>also</em> be inside of
“parent”.</p>
<p>However, if the <a href="trait.Subscriber.html" title="trait tracing::Subscriber"><code>Subscriber</code></a> only enables the <a href="struct.Level.html#associatedconstant.INFO" title="associated constant tracing::Level::INFO"><code>INFO</code></a> level, the “child”
span will be disabled. When the thread is spawned, the
<code>child_span.entered()</code> call will do nothing, since “child” is not
enabled. In this case, the “spawned a thread!” event occurs outside of
<em>any</em> span, since the “child” span was responsible for propagating its
parent to the spawned thread.</p>
<p>If this is not the desired behavior, <code>Span::or_current</code> can be used to
ensure that the “parent” span is propagated in both cases, either as a
parent of “child” <em>or</em> directly. For example:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>_parent_span = <span class="macro">tracing::info_span!</span>(<span class="string">"parent"</span>).entered();
<span class="comment">// ...
// If DEBUG is enabled, then "child" will be enabled, and `or_current`
// returns "child". Otherwise, if DEBUG is not enabled, "child" will be
// disabled, and `or_current` returns "parent".
</span><span class="kw">let </span>child_span = <span class="macro">tracing::debug_span!</span>(<span class="string">"child"</span>).or_current();
std::thread::spawn(<span class="kw">move </span>|| {
<span class="kw">let </span>_entered = child_span.entered();
<span class="macro">tracing::info!</span>(<span class="string">"spawned a thread!"</span>);
<span class="comment">// ...
</span>});</code></pre></div>
<p>When spawning <a href="stdlib/task/index.html" title="mod tracing::stdlib::task">asynchronous tasks</a>, <code>Span::or_current</code> can
be used similarly, in combination with <a href="trait.Instrument.html#method.instrument" title="method tracing::Instrument::instrument"><code>instrument</code></a>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::Instrument;
<span class="kw">let </span>_parent_span = <span class="macro">tracing::info_span!</span>(<span class="string">"parent"</span>).entered();
<span class="comment">// ...
</span><span class="kw">let </span>child_span = <span class="macro">tracing::debug_span!</span>(<span class="string">"child"</span>);
tokio::spawn(
<span class="kw">async </span>{
<span class="macro">tracing::info!</span>(<span class="string">"spawned a task!"</span>);
<span class="comment">// ...
</span>}.instrument(child_span.or_current())
);</code></pre></div>
<p>In general, <code>or_current</code> should be preferred over nesting an
<a href="trait.Instrument.html#method.instrument" title="method tracing::Instrument::instrument"><code>instrument</code></a> call inside of an <a href="trait.Instrument.html#method.in_current_span" title="method tracing::Instrument::in_current_span"><code>in_current_span</code></a> call, as using
<code>or_current</code> will be more efficient.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::Instrument;
<span class="kw">async fn </span>my_async_fn() {
<span class="comment">// ...
</span>}
<span class="kw">let </span>_parent_span = <span class="macro">tracing::info_span!</span>(<span class="string">"parent"</span>).entered();
<span class="comment">// Do this:
</span>tokio::spawn(
my_async_fn().instrument(<span class="macro">tracing::debug_span!</span>(<span class="string">"child"</span>).or_current())
);
<span class="comment">// ...rather than this:
</span>tokio::spawn(
my_async_fn()
.instrument(<span class="macro">tracing::debug_span!</span>(<span class="string">"child"</span>))
.in_current_span()
);</code></pre></div>
</div></details><section id="method.do_enter" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1035-1045">Source</a><h4 class="code-header">fn <a href="#method.do_enter" class="fn">do_enter</a>(&self)</h4></section><section id="method.do_exit" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1052-1062">Source</a><h4 class="code-header">fn <a href="#method.do_exit" class="fn">do_exit</a>(&self)</h4></section><details class="toggle method-toggle" open><summary><section id="method.in_scope" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1100-1103">Source</a><h4 class="code-header">pub fn <a href="#method.in_scope" class="fn">in_scope</a><F: <a class="trait" href="stdlib/ops/trait.FnOnce.html" title="trait tracing::stdlib::ops::FnOnce">FnOnce</a>() -> T, T>(&self, f: F) -> T</h4></section></summary><div class="docblock"><p>Executes the given function in the context of this span.</p>
<p>If this span is enabled, then this function enters the span, invokes <code>f</code>
and then exits the span. If the span is disabled, <code>f</code> will still be
invoked, but in the context of the currently-executing span (if there is
one).</p>
<p>Returns the result of evaluating <code>f</code>.</p>
<h5 id="examples-2"><a class="doc-anchor" href="#examples-2">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>my_span = <span class="macro">span!</span>(Level::TRACE, <span class="string">"my_span"</span>);
my_span.in_scope(|| {
<span class="comment">// this event occurs within the span.
</span><span class="macro">trace!</span>(<span class="string">"i'm in the span!"</span>);
});
<span class="comment">// this event occurs outside the span.
</span><span class="macro">trace!</span>(<span class="string">"i'm not in the span!"</span>);</code></pre></div>
<p>Calling a function and returning the result:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>hello_world() -> String {
<span class="string">"Hello world!"</span>.to_owned()
}
<span class="kw">let </span>span = <span class="macro">info_span!</span>(<span class="string">"hello_world"</span>);
<span class="comment">// the span will be entered for the duration of the call to
// `hello_world`.
</span><span class="kw">let </span>a_string = span.in_scope(hello_world);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.field" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1107-1109">Source</a><h4 class="code-header">pub fn <a href="#method.field" class="fn">field</a><Q: <a class="trait" href="field/trait.AsField.html" title="trait tracing::field::AsField">AsField</a> + ?<a class="trait" href="stdlib/marker/trait.Sized.html" title="trait tracing::stdlib::marker::Sized">Sized</a>>(&self, field: <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.reference.html">&Q</a>) -> <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><<a class="struct" href="field/struct.Field.html" title="struct tracing::field::Field">Field</a>></h4></section></summary><div class="docblock"><p>Returns a <a href="field/struct.Field.html" title="struct tracing::field::Field"><code>Field</code></a> for the field with the
given <code>name</code>, if one exists,</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.has_field" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1114-1116">Source</a><h4 class="code-header">pub fn <a href="#method.has_field" class="fn">has_field</a><Q: <a class="trait" href="field/trait.AsField.html" title="trait tracing::field::AsField">AsField</a> + ?<a class="trait" href="stdlib/marker/trait.Sized.html" title="trait tracing::stdlib::marker::Sized">Sized</a>>(&self, field: <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.reference.html">&Q</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns true if this <code>Span</code> has a field for the given
<a href="field/struct.Field.html" title="struct tracing::field::Field"><code>Field</code></a> or field name.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.record" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1188-1204">Source</a><h4 class="code-header">pub fn <a href="#method.record" class="fn">record</a><Q: <a class="trait" href="field/trait.AsField.html" title="trait tracing::field::AsField">AsField</a> + ?<a class="trait" href="stdlib/marker/trait.Sized.html" title="trait tracing::stdlib::marker::Sized">Sized</a>, V: <a class="trait" href="trait.Value.html" title="trait tracing::Value">Value</a>>(
&self,
field: <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.reference.html">&Q</a>,
value: V,
) -> &Self</h4></section></summary><div class="docblock"><p>Records that the field described by <code>field</code> has the value <code>value</code>.</p>
<p>This may be used with <a href="field/struct.Empty.html" title="struct tracing::field::Empty"><code>field::Empty</code></a> to declare fields whose values
are not known when the span is created, and record them later:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::{trace_span, field};
<span class="comment">// Create a span with two fields: `greeting`, with the value "hello world", and
// `parting`, without a value.
</span><span class="kw">let </span>span = <span class="macro">trace_span!</span>(<span class="string">"my_span"</span>, greeting = <span class="string">"hello world"</span>, parting = field::Empty);
<span class="comment">// ...
// Now, record a value for parting as well.
// (note that the field name is passed as a string slice)
</span>span.record(<span class="string">"parting"</span>, <span class="string">"goodbye world!"</span>);</code></pre></div>
<p>However, it may also be used to record a <em>new</em> value for a field whose
value was already recorded:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::info_span;
<span class="comment">// Initially, let's assume that our attempt to do something is going okay...
</span><span class="kw">let </span>span = <span class="macro">info_span!</span>(<span class="string">"doing_something"</span>, is_okay = <span class="bool-val">true</span>);
<span class="kw">let </span>_e = span.enter();
<span class="kw">match </span>do_something() {
<span class="prelude-val">Ok</span>(something) => {
<span class="comment">// ...
</span>}
<span class="prelude-val">Err</span>(<span class="kw">_</span>) => {
<span class="comment">// Things are no longer okay!
</span>span.record(<span class="string">"is_okay"</span>, <span class="bool-val">false</span>);
}
}</code></pre></div>
<pre class="ignore" style="white-space:normal;font:inherit;">
<strong>Note</strong>: The fields associated with a span are part
of its <a href="../struct.Metadata.html"><code>Metadata</code></a>.
The <a href="../struct.Metadata.html"><code>Metadata</code></a>
describing a particular span is constructed statically when the span
is created and cannot be extended later to add new fields. Therefore,
you cannot record a value for a field that was not specified when the
span was created:
</pre>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::{trace_span, field};
<span class="comment">// Create a span with two fields: `greeting`, with the value "hello world", and
// `parting`, without a value.
</span><span class="kw">let </span>span = <span class="macro">trace_span!</span>(<span class="string">"my_span"</span>, greeting = <span class="string">"hello world"</span>, parting = field::Empty);
<span class="comment">// ...
// Now, you try to record a value for a new field, `new_field`, which was not
// declared as `Empty` or populated when you created `span`.
// You won't get any error, but the assignment will have no effect!
</span>span.record(<span class="string">"new_field"</span>, <span class="string">"interesting_value_you_really_need"</span>);
<span class="comment">// Instead, all fields that may be recorded after span creation should be declared up front,
// using field::Empty when a value is not known, as we did for `parting`.
// This `record` call will indeed replace field::Empty with "you will be remembered".
</span>span.record(<span class="string">"parting"</span>, <span class="string">"you will be remembered"</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.record_all" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1207-1229">Source</a><h4 class="code-header">pub fn <a href="#method.record_all" class="fn">record_all</a>(&self, values: &<a class="struct" href="field/struct.ValueSet.html" title="struct tracing::field::ValueSet">ValueSet</a><'_>) -> &Self</h4></section></summary><div class="docblock"><p>Records all the fields in the provided <code>ValueSet</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_disabled" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1238-1240">Source</a><h4 class="code-header">pub fn <a href="#method.is_disabled" class="fn">is_disabled</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if this span was disabled by the subscriber and does not
exist.</p>
<p>See also <a href="struct.Span.html#method.is_none" title="method tracing::Span::is_none"><code>is_none</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_none" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1253-1255">Source</a><h4 class="code-header">pub fn <a href="#method.is_none" class="fn">is_none</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if this span was constructed by <a href="struct.Span.html#method.none" title="associated function tracing::Span::none"><code>Span::none</code></a> and is
empty.</p>
<p>If <code>is_none</code> returns <code>true</code> for a given span, then <a href="struct.Span.html#method.is_disabled" title="method tracing::Span::is_disabled"><code>is_disabled</code></a> will
also return <code>true</code>. However, when a span is disabled by the subscriber
rather than constructed by <code>Span::none</code>, this method will return
<code>false</code>, while <code>is_disabled</code> will return <code>true</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.follows_from" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1304-1311">Source</a><h4 class="code-header">pub fn <a href="#method.follows_from" class="fn">follows_from</a>(&self, from: impl <a class="trait" href="stdlib/convert/trait.Into.html" title="trait tracing::stdlib::convert::Into">Into</a><<a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><<a class="struct" href="span/struct.Id.html" title="struct tracing::span::Id">Id</a>>>) -> &Self</h4></section></summary><div class="docblock"><p>Indicates that the span with the given ID has an indirect causal
relationship with this span.</p>
<p>This relationship differs somewhat from the parent-child relationship: a
span may have any number of prior spans, rather than a single one; and
spans are not considered to be executing <em>inside</em> of the spans they
follow from. This means that a span may close even if subsequent spans
that follow from it are still open, and time spent inside of a
subsequent span should not be included in the time its precedents were
executing. This is used to model causal relationships such as when a
single future spawns several related background tasks, et cetera.</p>
<p>If this span is disabled, or the resulting follows-from relationship
would be invalid, this function will do nothing.</p>
<h5 id="examples-3"><a class="doc-anchor" href="#examples-3">§</a>Examples</h5>
<p>Setting a <code>follows_from</code> relationship with a <code>Span</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>span1 = <span class="macro">span!</span>(Level::INFO, <span class="string">"span_1"</span>);
<span class="kw">let </span>span2 = <span class="macro">span!</span>(Level::DEBUG, <span class="string">"span_2"</span>);
span2.follows_from(span1);</code></pre></div>
<p>Setting a <code>follows_from</code> relationship with the current span:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>span = <span class="macro">span!</span>(Level::INFO, <span class="string">"hello!"</span>);
span.follows_from(Span::current());</code></pre></div>
<p>Setting a <code>follows_from</code> relationship with a <code>Span</code> reference:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>span = <span class="macro">span!</span>(Level::INFO, <span class="string">"hello!"</span>);
<span class="kw">let </span>curr = Span::current();
span.follows_from(<span class="kw-2">&</span>curr);</code></pre></div>
<p>Setting a <code>follows_from</code> relationship with an <code>Id</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>span = <span class="macro">span!</span>(Level::INFO, <span class="string">"hello!"</span>);
<span class="kw">let </span>id = span.id();
span.follows_from(id);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.id" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1314-1316">Source</a><h4 class="code-header">pub fn <a href="#method.id" class="fn">id</a>(&self) -> <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><<a class="struct" href="span/struct.Id.html" title="struct tracing::span::Id">Id</a>></h4></section></summary><div class="docblock"><p>Returns this span’s <code>Id</code>, if it is enabled.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.metadata" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1319-1321">Source</a><h4 class="code-header">pub fn <a href="#method.metadata" class="fn">metadata</a>(&self) -> <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><&'static <a class="struct" href="struct.Metadata.html" title="struct tracing::Metadata">Metadata</a><'static>></h4></section></summary><div class="docblock"><p>Returns this span’s <code>Metadata</code>, if it is enabled.</p>
</div></details><section id="method.log" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1325-1355">Source</a><h4 class="code-header">fn <a href="#method.log" class="fn">log</a>(&self, target: &<a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.str.html">str</a>, level: <a class="enum" href="../log/enum.Level.html" title="enum log::Level">Level</a>, message: <a class="struct" href="stdlib/fmt/struct.Arguments.html" title="struct tracing::stdlib::fmt::Arguments">Arguments</a><'_>)</h4></section><details class="toggle method-toggle" open><summary><section id="method.with_subscriber" class="method"><a class="src rightside" href="../src/tracing/span.rs.html#1362-1366">Source</a><h4 class="code-header">pub fn <a href="#method.with_subscriber" class="fn">with_subscriber</a><T>(
&self,
f: impl <a class="trait" href="stdlib/ops/trait.FnOnce.html" title="trait tracing::stdlib::ops::FnOnce">FnOnce</a>((&<a class="struct" href="span/struct.Id.html" title="struct tracing::span::Id">Id</a>, &<a class="struct" href="struct.Dispatch.html" title="struct tracing::Dispatch">Dispatch</a>)) -> T,
) -> <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><T></h4></section></summary><div class="docblock"><p>Invokes a function with a reference to this span’s ID and subscriber.</p>
<p>if this span is enabled, the provided function is called, and the result is returned.
If the span is disabled, the function is not called, and this method returns <code>None</code>
instead.</p>
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Clone-for-Span" class="impl"><a class="src rightside" href="../src/tracing/span.rs.html#347">Source</a><a href="#impl-Clone-for-Span" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="stdlib/clone/trait.Clone.html" title="trait tracing::stdlib::clone::Clone">Clone</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.clone" class="method trait-impl"><a class="src rightside" href="../src/tracing/span.rs.html#347">Source</a><a href="#method.clone" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/clone/trait.Clone.html#tymethod.clone" class="fn">clone</a>(&self) -> <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h4></section></summary><div class='docblock'>Returns a copy of the value. <a href="stdlib/clone/trait.Clone.html#tymethod.clone">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_from" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.85.0/src/core/clone.rs.html#174">Source</a></span><a href="#method.clone_from" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/clone/trait.Clone.html#method.clone_from" class="fn">clone_from</a>(&mut self, source: &Self)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a href="stdlib/clone/trait.Clone.html#method.clone_from">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-Span" class="impl"><a class="src rightside" href="../src/tracing/span.rs.html#1386-1417">Source</a><a href="#impl-Debug-for-Span" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="stdlib/fmt/trait.Debug.html" title="trait tracing::stdlib::fmt::Debug">Debug</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../src/tracing/span.rs.html#1387-1416">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="stdlib/fmt/struct.Formatter.html" title="struct tracing::stdlib::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="stdlib/fmt/type.Result.html" title="type tracing::stdlib::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="stdlib/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Drop-for-Span" class="impl"><a class="src rightside" href="../src/tracing/span.rs.html#1449-1470">Source</a><a href="#impl-Drop-for-Span" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="stdlib/ops/trait.Drop.html" title="trait tracing::stdlib::ops::Drop">Drop</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.drop" class="method trait-impl"><a class="src rightside" href="../src/tracing/span.rs.html#1451-1469">Source</a><a href="#method.drop" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/ops/trait.Drop.html#tymethod.drop" class="fn">drop</a>(&mut self)</h4></section></summary><div class='docblock'>Executes the destructor for this type. <a href="stdlib/ops/trait.Drop.html#tymethod.drop">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-From%3C%26Span%3E-for-Option%3C%26Id%3E" class="impl"><a class="src rightside" href="../src/tracing/span.rs.html#1419-1423">Source</a><a href="#impl-From%3C%26Span%3E-for-Option%3C%26Id%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="stdlib/convert/trait.From.html" title="trait tracing::stdlib::convert::From">From</a><&'a <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a>> for <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><&'a <a class="struct" href="span/struct.Id.html" title="struct tracing::span::Id">Id</a>></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="../src/tracing/span.rs.html#1420-1422">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/convert/trait.From.html#tymethod.from" class="fn">from</a>(span: &'a <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a>) -> Self</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-From%3C%26Span%3E-for-Option%3CId%3E" class="impl"><a class="src rightside" href="../src/tracing/span.rs.html#1425-1429">Source</a><a href="#impl-From%3C%26Span%3E-for-Option%3CId%3E" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="stdlib/convert/trait.From.html" title="trait tracing::stdlib::convert::From">From</a><&'a <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a>> for <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><<a class="struct" href="span/struct.Id.html" title="struct tracing::span::Id">Id</a>></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from-1" class="method trait-impl"><a class="src rightside" href="../src/tracing/span.rs.html#1426-1428">Source</a><a href="#method.from-1" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/convert/trait.From.html#tymethod.from" class="fn">from</a>(span: &'a <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a>) -> Self</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-From%3CSpan%3E-for-Option%3CId%3E" class="impl"><a class="src rightside" href="../src/tracing/span.rs.html#1431-1435">Source</a><a href="#impl-From%3CSpan%3E-for-Option%3CId%3E" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="stdlib/convert/trait.From.html" title="trait tracing::stdlib::convert::From">From</a><<a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a>> for <a class="enum" href="stdlib/option/enum.Option.html" title="enum tracing::stdlib::option::Option">Option</a><<a class="struct" href="span/struct.Id.html" title="struct tracing::span::Id">Id</a>></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from-2" class="method trait-impl"><a class="src rightside" href="../src/tracing/span.rs.html#1432-1434">Source</a><a href="#method.from-2" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/convert/trait.From.html#tymethod.from" class="fn">from</a>(span: <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a>) -> Self</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Hash-for-Span" class="impl"><a class="src rightside" href="../src/tracing/span.rs.html#1380-1384">Source</a><a href="#impl-Hash-for-Span" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="stdlib/hash/trait.Hash.html" title="trait tracing::stdlib::hash::Hash">Hash</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.hash" class="method trait-impl"><a class="src rightside" href="../src/tracing/span.rs.html#1381-1383">Source</a><a href="#method.hash" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/hash/trait.Hash.html#tymethod.hash" class="fn">hash</a><H: <a class="trait" href="stdlib/hash/trait.Hasher.html" title="trait tracing::stdlib::hash::Hasher">Hasher</a>>(&self, hasher: <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.reference.html">&mut H</a>)</h4></section></summary><div class='docblock'>Feeds this value into the given <a href="stdlib/hash/trait.Hasher.html" title="trait tracing::stdlib::hash::Hasher"><code>Hasher</code></a>. <a href="stdlib/hash/trait.Hash.html#tymethod.hash">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.hash_slice" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.3.0">1.3.0</span> · <a class="src" href="https://doc.rust-lang.org/1.85.0/src/core/hash/mod.rs.html#235-237">Source</a></span><a href="#method.hash_slice" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/hash/trait.Hash.html#method.hash_slice" class="fn">hash_slice</a><H>(data: &[Self], state: <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.reference.html">&mut H</a>)<div class="where">where
H: <a class="trait" href="stdlib/hash/trait.Hasher.html" title="trait tracing::stdlib::hash::Hasher">Hasher</a>,
Self: <a class="trait" href="stdlib/marker/trait.Sized.html" title="trait tracing::stdlib::marker::Sized">Sized</a>,</div></h4></section></summary><div class='docblock'>Feeds a slice of this type into the given <a href="stdlib/hash/trait.Hasher.html" title="trait tracing::stdlib::hash::Hasher"><code>Hasher</code></a>. <a href="stdlib/hash/trait.Hash.html#method.hash_slice">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-PartialEq-for-Span" class="impl"><a class="src rightside" href="../src/tracing/span.rs.html#1369-1378">Source</a><a href="#impl-PartialEq-for-Span" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="stdlib/cmp/trait.PartialEq.html" title="trait tracing::stdlib::cmp::PartialEq">PartialEq</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.eq" class="method trait-impl"><a class="src rightside" href="../src/tracing/span.rs.html#1370-1377">Source</a><a href="#method.eq" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/cmp/trait.PartialEq.html#tymethod.eq" class="fn">eq</a>(&self, other: &Self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>.</div></details><details class="toggle method-toggle" open><summary><section id="method.ne" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.85.0/src/core/cmp.rs.html#261">Source</a></span><a href="#method.ne" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/cmp/trait.PartialEq.html#method.ne" class="fn">ne</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.reference.html">&Rhs</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Tests for <code>!=</code>. The default implementation is almost always sufficient,
and should not be overridden without very good reason.</div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-Span" class="impl"><a href="#impl-Freeze-for-Span" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="stdlib/marker/trait.Freeze.html" title="trait tracing::stdlib::marker::Freeze">Freeze</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section><section id="impl-RefUnwindSafe-for-Span" class="impl"><a href="#impl-RefUnwindSafe-for-Span" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="stdlib/panic/trait.RefUnwindSafe.html" title="trait tracing::stdlib::panic::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section><section id="impl-Send-for-Span" class="impl"><a href="#impl-Send-for-Span" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="stdlib/marker/trait.Send.html" title="trait tracing::stdlib::marker::Send">Send</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section><section id="impl-Sync-for-Span" class="impl"><a href="#impl-Sync-for-Span" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="stdlib/marker/trait.Sync.html" title="trait tracing::stdlib::marker::Sync">Sync</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section><section id="impl-Unpin-for-Span" class="impl"><a href="#impl-Unpin-for-Span" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="stdlib/marker/trait.Unpin.html" title="trait tracing::stdlib::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section><section id="impl-UnwindSafe-for-Span" class="impl"><a href="#impl-UnwindSafe-for-Span" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="stdlib/panic/trait.UnwindSafe.html" title="trait tracing::stdlib::panic::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/any.rs.html#138">Source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="stdlib/any/trait.Any.html" title="trait tracing::stdlib::any::Any">Any</a> for T<div class="where">where
T: 'static + ?<a class="trait" href="stdlib/marker/trait.Sized.html" title="trait tracing::stdlib::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/any.rs.html#139">Source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="stdlib/any/struct.TypeId.html" title="struct tracing::stdlib::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="stdlib/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/borrow.rs.html#209">Source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="stdlib/borrow/trait.Borrow.html" title="trait tracing::stdlib::borrow::Borrow">Borrow</a><T> for T<div class="where">where
T: ?<a class="trait" href="stdlib/marker/trait.Sized.html" title="trait tracing::stdlib::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/borrow.rs.html#211">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="stdlib/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/borrow.rs.html#217">Source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="stdlib/borrow/trait.BorrowMut.html" title="trait tracing::stdlib::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
T: ?<a class="trait" href="stdlib/marker/trait.Sized.html" title="trait tracing::stdlib::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/borrow.rs.html#218">Source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="stdlib/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-CloneToUninit-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/clone.rs.html#273">Source</a><a href="#impl-CloneToUninit-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="stdlib/clone/trait.CloneToUninit.html" title="trait tracing::stdlib::clone::CloneToUninit">CloneToUninit</a> for T<div class="where">where
T: <a class="trait" href="stdlib/clone/trait.Clone.html" title="trait tracing::stdlib::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.clone_to_uninit" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/clone.rs.html#275">Source</a><a href="#method.clone_to_uninit" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="stdlib/clone/trait.CloneToUninit.html#tymethod.clone_to_uninit" class="fn">clone_to_uninit</a>(&self, dst: <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.pointer.html">*mut </a><a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.u8.html">u8</a>)</h4></section></summary><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>clone_to_uninit</code> <a href="https://github.com/tokio-rs/tracing/issues/126799">#126799</a>)</span></div></span><div class='docblock'>Performs copy-assignment from <code>self</code> to <code>dst</code>. <a href="stdlib/clone/trait.CloneToUninit.html#tymethod.clone_to_uninit">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/convert/mod.rs.html#767">Source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="stdlib/convert/trait.From.html" title="trait tracing::stdlib::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from-3" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/convert/mod.rs.html#770">Source</a><a href="#method.from-3" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Instrument-for-T" class="impl"><a class="src rightside" href="../src/tracing/instrument.rs.html#325">Source</a><a href="#impl-Instrument-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="trait.Instrument.html" title="trait tracing::Instrument">Instrument</a> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.instrument" class="method trait-impl"><a class="src rightside" href="../src/tracing/instrument.rs.html#86-91">Source</a><a href="#method.instrument" class="anchor">§</a><h4 class="code-header">fn <a href="trait.Instrument.html#method.instrument" class="fn">instrument</a>(self, span: <a class="struct" href="struct.Span.html" title="struct tracing::Span">Span</a>) -> <a class="struct" href="instrument/struct.Instrumented.html" title="struct tracing::instrument::Instrumented">Instrumented</a><Self> <a href="#" class="tooltip" data-notable-ty="Instrumented<Self>">ⓘ</a></h4></section></summary><div class='docblock'>Instruments this type with the provided <a href="struct.Span.html" title="struct tracing::Span"><code>Span</code></a>, returning an
<code>Instrumented</code> wrapper. <a href="trait.Instrument.html#method.instrument">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.in_current_span" class="method trait-impl"><a class="src rightside" href="../src/tracing/instrument.rs.html#128-130">Source</a><a href="#method.in_current_span" class="anchor">§</a><h4 class="code-header">fn <a href="trait.Instrument.html#method.in_current_span" class="fn">in_current_span</a>(self) -> <a class="struct" href="instrument/struct.Instrumented.html" title="struct tracing::instrument::Instrumented">Instrumented</a><Self> <a href="#" class="tooltip" data-notable-ty="Instrumented<Self>">ⓘ</a></h4></section></summary><div class='docblock'>Instruments this type with the <a href="struct.Span.html#method.current" title="associated function tracing::Span::current">current</a> <a href="struct.Span.html" title="struct tracing::Span"><code>Span</code></a>, returning an
<code>Instrumented</code> wrapper. <a href="trait.Instrument.html#method.in_current_span">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/convert/mod.rs.html#750-752">Source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="stdlib/convert/trait.Into.html" title="trait tracing::stdlib::convert::Into">Into</a><U> for T<div class="where">where
U: <a class="trait" href="stdlib/convert/trait.From.html" title="trait tracing::stdlib::convert::From">From</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/convert/mod.rs.html#760">Source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
<p>That is, this conversion is whatever the implementation of
<code><a href="stdlib/convert/trait.From.html" title="trait tracing::stdlib::convert::From">From</a><T> for U</code> chooses to do.</p>
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-ToOwned-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/alloc/borrow.rs.html#82-84">Source</a><a href="#impl-ToOwned-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="stdlib/borrow/trait.ToOwned.html" title="trait tracing::stdlib::borrow::ToOwned">ToOwned</a> for T<div class="where">where
T: <a class="trait" href="stdlib/clone/trait.Clone.html" title="trait tracing::stdlib::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/alloc/borrow.rs.html#86">Source</a><a href="#associatedtype.Owned" class="anchor">§</a><h4 class="code-header">type <a href="stdlib/borrow/trait.ToOwned.html#associatedtype.Owned" class="associatedtype">Owned</a> = T</h4></section></summary><div class='docblock'>The resulting type after obtaining ownership.</div></details><details class="toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/alloc/borrow.rs.html#87">Source</a><a href="#method.to_owned" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/borrow/trait.ToOwned.html#tymethod.to_owned" class="fn">to_owned</a>(&self) -> T</h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a href="stdlib/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/alloc/borrow.rs.html#91">Source</a><a href="#method.clone_into" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/borrow/trait.ToOwned.html#method.clone_into" class="fn">clone_into</a>(&self, target: <a class="primitive" href="https://doc.rust-lang.org/1.85.0/std/primitive.reference.html">&mut T</a>)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a href="stdlib/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/convert/mod.rs.html#807-809">Source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="stdlib/convert/trait.TryFrom.html" title="trait tracing::stdlib::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
U: <a class="trait" href="stdlib/convert/trait.Into.html" title="trait tracing::stdlib::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/convert/mod.rs.html#811">Source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="stdlib/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="stdlib/convert/enum.Infallible.html" title="enum tracing::stdlib::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/convert/mod.rs.html#814">Source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="stdlib/result/enum.Result.html" title="enum tracing::stdlib::result::Result">Result</a><T, <T as <a class="trait" href="stdlib/convert/trait.TryFrom.html" title="trait tracing::stdlib::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="stdlib/convert/trait.TryFrom.html#associatedtype.Error" title="type tracing::stdlib::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/convert/mod.rs.html#792-794">Source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="stdlib/convert/trait.TryInto.html" title="trait tracing::stdlib::convert::TryInto">TryInto</a><U> for T<div class="where">where
U: <a class="trait" href="stdlib/convert/trait.TryFrom.html" title="trait tracing::stdlib::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/convert/mod.rs.html#796">Source</a><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="stdlib/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="stdlib/convert/trait.TryFrom.html" title="trait tracing::stdlib::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="stdlib/convert/trait.TryFrom.html#associatedtype.Error" title="type tracing::stdlib::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.85.0/src/core/convert/mod.rs.html#799">Source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="stdlib/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="stdlib/result/enum.Result.html" title="enum tracing::stdlib::result::Result">Result</a><U, <U as <a class="trait" href="stdlib/convert/trait.TryFrom.html" title="trait tracing::stdlib::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="stdlib/convert/trait.TryFrom.html#associatedtype.Error" title="type tracing::stdlib::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-WithSubscriber-for-T" class="impl"><a class="src rightside" href="../src/tracing/instrument.rs.html#393">Source</a><a href="#impl-WithSubscriber-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="instrument/trait.WithSubscriber.html" title="trait tracing::instrument::WithSubscriber">WithSubscriber</a> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.with_subscriber-1" class="method trait-impl"><a class="src rightside" href="../src/tracing/instrument.rs.html#176-184">Source</a><a href="#method.with_subscriber-1" class="anchor">§</a><h4 class="code-header">fn <a href="instrument/trait.WithSubscriber.html#method.with_subscriber" class="fn">with_subscriber</a><S>(self, subscriber: S) -> <a class="struct" href="instrument/struct.WithDispatch.html" title="struct tracing::instrument::WithDispatch">WithDispatch</a><Self> <a href="#" class="tooltip" data-notable-ty="WithDispatch<Self>">ⓘ</a><div class="where">where
S: <a class="trait" href="stdlib/convert/trait.Into.html" title="trait tracing::stdlib::convert::Into">Into</a><<a class="struct" href="struct.Dispatch.html" title="struct tracing::Dispatch">Dispatch</a>>,</div></h4></section></summary><div class='docblock'>Attaches the provided <a href="trait.Subscriber.html" title="trait tracing::Subscriber"><code>Subscriber</code></a> to this type, returning a
<a href="instrument/struct.WithDispatch.html" title="struct tracing::instrument::WithDispatch"><code>WithDispatch</code></a> wrapper. <a href="instrument/trait.WithSubscriber.html#method.with_subscriber">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.with_current_subscriber" class="method trait-impl"><a class="src rightside" href="../src/tracing/instrument.rs.html#228-233">Source</a><a href="#method.with_current_subscriber" class="anchor">§</a><h4 class="code-header">fn <a href="instrument/trait.WithSubscriber.html#method.with_current_subscriber" class="fn">with_current_subscriber</a>(self) -> <a class="struct" href="instrument/struct.WithDispatch.html" title="struct tracing::instrument::WithDispatch">WithDispatch</a><Self> <a href="#" class="tooltip" data-notable-ty="WithDispatch<Self>">ⓘ</a></h4></section></summary><div class='docblock'>Attaches the current <a href="dispatcher/index.html#setting-the-default-subscriber" title="mod tracing::dispatcher">default</a> <a href="trait.Subscriber.html" title="trait tracing::Subscriber"><code>Subscriber</code></a> to this type, returning a
<a href="instrument/struct.WithDispatch.html" title="struct tracing::instrument::WithDispatch"><code>WithDispatch</code></a> wrapper. <a href="instrument/trait.WithSubscriber.html#method.with_current_subscriber">Read more</a></div></details></div></details></div><script type="text/json" id="notable-traits-data">{"Instrumented<Self>":"<h3>Notable traits for <code><a class=\"struct\" href=\"instrument/struct.Instrumented.html\" title=\"struct tracing::instrument::Instrumented\">Instrumented</a><T></code></h3><pre><code><div class=\"where\">impl<T: <a class=\"trait\" href=\"stdlib/future/trait.Future.html\" title=\"trait tracing::stdlib::future::Future\">Future</a>> <a class=\"trait\" href=\"stdlib/future/trait.Future.html\" title=\"trait tracing::stdlib::future::Future\">Future</a> for <a class=\"struct\" href=\"instrument/struct.Instrumented.html\" title=\"struct tracing::instrument::Instrumented\">Instrumented</a><T></div><div class=\"where\"> type <a href=\"stdlib/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</a> = T::<a class=\"associatedtype\" href=\"stdlib/future/trait.Future.html#associatedtype.Output\" title=\"type tracing::stdlib::future::Future::Output\">Output</a>;</div>","WithDispatch<Self>":"<h3>Notable traits for <code><a class=\"struct\" href=\"instrument/struct.WithDispatch.html\" title=\"struct tracing::instrument::WithDispatch\">WithDispatch</a><T></code></h3><pre><code><div class=\"where\">impl<T: <a class=\"trait\" href=\"stdlib/future/trait.Future.html\" title=\"trait tracing::stdlib::future::Future\">Future</a>> <a class=\"trait\" href=\"stdlib/future/trait.Future.html\" title=\"trait tracing::stdlib::future::Future\">Future</a> for <a class=\"struct\" href=\"instrument/struct.WithDispatch.html\" title=\"struct tracing::instrument::WithDispatch\">WithDispatch</a><T></div><div class=\"where\"> type <a href=\"stdlib/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</a> = T::<a class=\"associatedtype\" href=\"stdlib/future/trait.Future.html#associatedtype.Output\" title=\"type tracing::stdlib::future::Future::Output\">Output</a>;</div>"}</script></section></div></main></body></html>