blob: daf0ab6718f4c35e10e4645e51adf3548f10e4b4 [file] [log] [blame]
<!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="Source of the Rust file `/root/.cargo/registry/src/github.com-1ecc6299db9ec823/tracing-core-0.1.31/src/callsite.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>callsite.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../source-script.js"></script><script defer src="../../source-files.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><a class="sidebar-logo" href="../../tracing_core/index.html"><div class="logo-container">
<img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></div></a></nav><main><div class="width-limiter"><nav class="sub"><a class="sub-logo-container" href="../../tracing_core/index.html">
<img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></a><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><pre class="src-line-numbers"><span id="1">1</span>
<span id="2">2</span>
<span id="3">3</span>
<span id="4">4</span>
<span id="5">5</span>
<span id="6">6</span>
<span id="7">7</span>
<span id="8">8</span>
<span id="9">9</span>
<span id="10">10</span>
<span id="11">11</span>
<span id="12">12</span>
<span id="13">13</span>
<span id="14">14</span>
<span id="15">15</span>
<span id="16">16</span>
<span id="17">17</span>
<span id="18">18</span>
<span id="19">19</span>
<span id="20">20</span>
<span id="21">21</span>
<span id="22">22</span>
<span id="23">23</span>
<span id="24">24</span>
<span id="25">25</span>
<span id="26">26</span>
<span id="27">27</span>
<span id="28">28</span>
<span id="29">29</span>
<span id="30">30</span>
<span id="31">31</span>
<span id="32">32</span>
<span id="33">33</span>
<span id="34">34</span>
<span id="35">35</span>
<span id="36">36</span>
<span id="37">37</span>
<span id="38">38</span>
<span id="39">39</span>
<span id="40">40</span>
<span id="41">41</span>
<span id="42">42</span>
<span id="43">43</span>
<span id="44">44</span>
<span id="45">45</span>
<span id="46">46</span>
<span id="47">47</span>
<span id="48">48</span>
<span id="49">49</span>
<span id="50">50</span>
<span id="51">51</span>
<span id="52">52</span>
<span id="53">53</span>
<span id="54">54</span>
<span id="55">55</span>
<span id="56">56</span>
<span id="57">57</span>
<span id="58">58</span>
<span id="59">59</span>
<span id="60">60</span>
<span id="61">61</span>
<span id="62">62</span>
<span id="63">63</span>
<span id="64">64</span>
<span id="65">65</span>
<span id="66">66</span>
<span id="67">67</span>
<span id="68">68</span>
<span id="69">69</span>
<span id="70">70</span>
<span id="71">71</span>
<span id="72">72</span>
<span id="73">73</span>
<span id="74">74</span>
<span id="75">75</span>
<span id="76">76</span>
<span id="77">77</span>
<span id="78">78</span>
<span id="79">79</span>
<span id="80">80</span>
<span id="81">81</span>
<span id="82">82</span>
<span id="83">83</span>
<span id="84">84</span>
<span id="85">85</span>
<span id="86">86</span>
<span id="87">87</span>
<span id="88">88</span>
<span id="89">89</span>
<span id="90">90</span>
<span id="91">91</span>
<span id="92">92</span>
<span id="93">93</span>
<span id="94">94</span>
<span id="95">95</span>
<span id="96">96</span>
<span id="97">97</span>
<span id="98">98</span>
<span id="99">99</span>
<span id="100">100</span>
<span id="101">101</span>
<span id="102">102</span>
<span id="103">103</span>
<span id="104">104</span>
<span id="105">105</span>
<span id="106">106</span>
<span id="107">107</span>
<span id="108">108</span>
<span id="109">109</span>
<span id="110">110</span>
<span id="111">111</span>
<span id="112">112</span>
<span id="113">113</span>
<span id="114">114</span>
<span id="115">115</span>
<span id="116">116</span>
<span id="117">117</span>
<span id="118">118</span>
<span id="119">119</span>
<span id="120">120</span>
<span id="121">121</span>
<span id="122">122</span>
<span id="123">123</span>
<span id="124">124</span>
<span id="125">125</span>
<span id="126">126</span>
<span id="127">127</span>
<span id="128">128</span>
<span id="129">129</span>
<span id="130">130</span>
<span id="131">131</span>
<span id="132">132</span>
<span id="133">133</span>
<span id="134">134</span>
<span id="135">135</span>
<span id="136">136</span>
<span id="137">137</span>
<span id="138">138</span>
<span id="139">139</span>
<span id="140">140</span>
<span id="141">141</span>
<span id="142">142</span>
<span id="143">143</span>
<span id="144">144</span>
<span id="145">145</span>
<span id="146">146</span>
<span id="147">147</span>
<span id="148">148</span>
<span id="149">149</span>
<span id="150">150</span>
<span id="151">151</span>
<span id="152">152</span>
<span id="153">153</span>
<span id="154">154</span>
<span id="155">155</span>
<span id="156">156</span>
<span id="157">157</span>
<span id="158">158</span>
<span id="159">159</span>
<span id="160">160</span>
<span id="161">161</span>
<span id="162">162</span>
<span id="163">163</span>
<span id="164">164</span>
<span id="165">165</span>
<span id="166">166</span>
<span id="167">167</span>
<span id="168">168</span>
<span id="169">169</span>
<span id="170">170</span>
<span id="171">171</span>
<span id="172">172</span>
<span id="173">173</span>
<span id="174">174</span>
<span id="175">175</span>
<span id="176">176</span>
<span id="177">177</span>
<span id="178">178</span>
<span id="179">179</span>
<span id="180">180</span>
<span id="181">181</span>
<span id="182">182</span>
<span id="183">183</span>
<span id="184">184</span>
<span id="185">185</span>
<span id="186">186</span>
<span id="187">187</span>
<span id="188">188</span>
<span id="189">189</span>
<span id="190">190</span>
<span id="191">191</span>
<span id="192">192</span>
<span id="193">193</span>
<span id="194">194</span>
<span id="195">195</span>
<span id="196">196</span>
<span id="197">197</span>
<span id="198">198</span>
<span id="199">199</span>
<span id="200">200</span>
<span id="201">201</span>
<span id="202">202</span>
<span id="203">203</span>
<span id="204">204</span>
<span id="205">205</span>
<span id="206">206</span>
<span id="207">207</span>
<span id="208">208</span>
<span id="209">209</span>
<span id="210">210</span>
<span id="211">211</span>
<span id="212">212</span>
<span id="213">213</span>
<span id="214">214</span>
<span id="215">215</span>
<span id="216">216</span>
<span id="217">217</span>
<span id="218">218</span>
<span id="219">219</span>
<span id="220">220</span>
<span id="221">221</span>
<span id="222">222</span>
<span id="223">223</span>
<span id="224">224</span>
<span id="225">225</span>
<span id="226">226</span>
<span id="227">227</span>
<span id="228">228</span>
<span id="229">229</span>
<span id="230">230</span>
<span id="231">231</span>
<span id="232">232</span>
<span id="233">233</span>
<span id="234">234</span>
<span id="235">235</span>
<span id="236">236</span>
<span id="237">237</span>
<span id="238">238</span>
<span id="239">239</span>
<span id="240">240</span>
<span id="241">241</span>
<span id="242">242</span>
<span id="243">243</span>
<span id="244">244</span>
<span id="245">245</span>
<span id="246">246</span>
<span id="247">247</span>
<span id="248">248</span>
<span id="249">249</span>
<span id="250">250</span>
<span id="251">251</span>
<span id="252">252</span>
<span id="253">253</span>
<span id="254">254</span>
<span id="255">255</span>
<span id="256">256</span>
<span id="257">257</span>
<span id="258">258</span>
<span id="259">259</span>
<span id="260">260</span>
<span id="261">261</span>
<span id="262">262</span>
<span id="263">263</span>
<span id="264">264</span>
<span id="265">265</span>
<span id="266">266</span>
<span id="267">267</span>
<span id="268">268</span>
<span id="269">269</span>
<span id="270">270</span>
<span id="271">271</span>
<span id="272">272</span>
<span id="273">273</span>
<span id="274">274</span>
<span id="275">275</span>
<span id="276">276</span>
<span id="277">277</span>
<span id="278">278</span>
<span id="279">279</span>
<span id="280">280</span>
<span id="281">281</span>
<span id="282">282</span>
<span id="283">283</span>
<span id="284">284</span>
<span id="285">285</span>
<span id="286">286</span>
<span id="287">287</span>
<span id="288">288</span>
<span id="289">289</span>
<span id="290">290</span>
<span id="291">291</span>
<span id="292">292</span>
<span id="293">293</span>
<span id="294">294</span>
<span id="295">295</span>
<span id="296">296</span>
<span id="297">297</span>
<span id="298">298</span>
<span id="299">299</span>
<span id="300">300</span>
<span id="301">301</span>
<span id="302">302</span>
<span id="303">303</span>
<span id="304">304</span>
<span id="305">305</span>
<span id="306">306</span>
<span id="307">307</span>
<span id="308">308</span>
<span id="309">309</span>
<span id="310">310</span>
<span id="311">311</span>
<span id="312">312</span>
<span id="313">313</span>
<span id="314">314</span>
<span id="315">315</span>
<span id="316">316</span>
<span id="317">317</span>
<span id="318">318</span>
<span id="319">319</span>
<span id="320">320</span>
<span id="321">321</span>
<span id="322">322</span>
<span id="323">323</span>
<span id="324">324</span>
<span id="325">325</span>
<span id="326">326</span>
<span id="327">327</span>
<span id="328">328</span>
<span id="329">329</span>
<span id="330">330</span>
<span id="331">331</span>
<span id="332">332</span>
<span id="333">333</span>
<span id="334">334</span>
<span id="335">335</span>
<span id="336">336</span>
<span id="337">337</span>
<span id="338">338</span>
<span id="339">339</span>
<span id="340">340</span>
<span id="341">341</span>
<span id="342">342</span>
<span id="343">343</span>
<span id="344">344</span>
<span id="345">345</span>
<span id="346">346</span>
<span id="347">347</span>
<span id="348">348</span>
<span id="349">349</span>
<span id="350">350</span>
<span id="351">351</span>
<span id="352">352</span>
<span id="353">353</span>
<span id="354">354</span>
<span id="355">355</span>
<span id="356">356</span>
<span id="357">357</span>
<span id="358">358</span>
<span id="359">359</span>
<span id="360">360</span>
<span id="361">361</span>
<span id="362">362</span>
<span id="363">363</span>
<span id="364">364</span>
<span id="365">365</span>
<span id="366">366</span>
<span id="367">367</span>
<span id="368">368</span>
<span id="369">369</span>
<span id="370">370</span>
<span id="371">371</span>
<span id="372">372</span>
<span id="373">373</span>
<span id="374">374</span>
<span id="375">375</span>
<span id="376">376</span>
<span id="377">377</span>
<span id="378">378</span>
<span id="379">379</span>
<span id="380">380</span>
<span id="381">381</span>
<span id="382">382</span>
<span id="383">383</span>
<span id="384">384</span>
<span id="385">385</span>
<span id="386">386</span>
<span id="387">387</span>
<span id="388">388</span>
<span id="389">389</span>
<span id="390">390</span>
<span id="391">391</span>
<span id="392">392</span>
<span id="393">393</span>
<span id="394">394</span>
<span id="395">395</span>
<span id="396">396</span>
<span id="397">397</span>
<span id="398">398</span>
<span id="399">399</span>
<span id="400">400</span>
<span id="401">401</span>
<span id="402">402</span>
<span id="403">403</span>
<span id="404">404</span>
<span id="405">405</span>
<span id="406">406</span>
<span id="407">407</span>
<span id="408">408</span>
<span id="409">409</span>
<span id="410">410</span>
<span id="411">411</span>
<span id="412">412</span>
<span id="413">413</span>
<span id="414">414</span>
<span id="415">415</span>
<span id="416">416</span>
<span id="417">417</span>
<span id="418">418</span>
<span id="419">419</span>
<span id="420">420</span>
<span id="421">421</span>
<span id="422">422</span>
<span id="423">423</span>
<span id="424">424</span>
<span id="425">425</span>
<span id="426">426</span>
<span id="427">427</span>
<span id="428">428</span>
<span id="429">429</span>
<span id="430">430</span>
<span id="431">431</span>
<span id="432">432</span>
<span id="433">433</span>
<span id="434">434</span>
<span id="435">435</span>
<span id="436">436</span>
<span id="437">437</span>
<span id="438">438</span>
<span id="439">439</span>
<span id="440">440</span>
<span id="441">441</span>
<span id="442">442</span>
<span id="443">443</span>
<span id="444">444</span>
<span id="445">445</span>
<span id="446">446</span>
<span id="447">447</span>
<span id="448">448</span>
<span id="449">449</span>
<span id="450">450</span>
<span id="451">451</span>
<span id="452">452</span>
<span id="453">453</span>
<span id="454">454</span>
<span id="455">455</span>
<span id="456">456</span>
<span id="457">457</span>
<span id="458">458</span>
<span id="459">459</span>
<span id="460">460</span>
<span id="461">461</span>
<span id="462">462</span>
<span id="463">463</span>
<span id="464">464</span>
<span id="465">465</span>
<span id="466">466</span>
<span id="467">467</span>
<span id="468">468</span>
<span id="469">469</span>
<span id="470">470</span>
<span id="471">471</span>
<span id="472">472</span>
<span id="473">473</span>
<span id="474">474</span>
<span id="475">475</span>
<span id="476">476</span>
<span id="477">477</span>
<span id="478">478</span>
<span id="479">479</span>
<span id="480">480</span>
<span id="481">481</span>
<span id="482">482</span>
<span id="483">483</span>
<span id="484">484</span>
<span id="485">485</span>
<span id="486">486</span>
<span id="487">487</span>
<span id="488">488</span>
<span id="489">489</span>
<span id="490">490</span>
<span id="491">491</span>
<span id="492">492</span>
<span id="493">493</span>
<span id="494">494</span>
<span id="495">495</span>
<span id="496">496</span>
<span id="497">497</span>
<span id="498">498</span>
<span id="499">499</span>
<span id="500">500</span>
<span id="501">501</span>
<span id="502">502</span>
<span id="503">503</span>
<span id="504">504</span>
<span id="505">505</span>
<span id="506">506</span>
<span id="507">507</span>
<span id="508">508</span>
<span id="509">509</span>
<span id="510">510</span>
<span id="511">511</span>
<span id="512">512</span>
<span id="513">513</span>
<span id="514">514</span>
<span id="515">515</span>
<span id="516">516</span>
<span id="517">517</span>
<span id="518">518</span>
<span id="519">519</span>
<span id="520">520</span>
<span id="521">521</span>
<span id="522">522</span>
<span id="523">523</span>
<span id="524">524</span>
<span id="525">525</span>
<span id="526">526</span>
<span id="527">527</span>
<span id="528">528</span>
<span id="529">529</span>
<span id="530">530</span>
<span id="531">531</span>
<span id="532">532</span>
<span id="533">533</span>
<span id="534">534</span>
<span id="535">535</span>
<span id="536">536</span>
<span id="537">537</span>
<span id="538">538</span>
<span id="539">539</span>
<span id="540">540</span>
<span id="541">541</span>
<span id="542">542</span>
<span id="543">543</span>
<span id="544">544</span>
<span id="545">545</span>
<span id="546">546</span>
<span id="547">547</span>
<span id="548">548</span>
<span id="549">549</span>
<span id="550">550</span>
<span id="551">551</span>
<span id="552">552</span>
<span id="553">553</span>
<span id="554">554</span>
<span id="555">555</span>
<span id="556">556</span>
<span id="557">557</span>
<span id="558">558</span>
<span id="559">559</span>
<span id="560">560</span>
<span id="561">561</span>
<span id="562">562</span>
<span id="563">563</span>
<span id="564">564</span>
<span id="565">565</span>
<span id="566">566</span>
<span id="567">567</span>
<span id="568">568</span>
<span id="569">569</span>
<span id="570">570</span>
<span id="571">571</span>
<span id="572">572</span>
<span id="573">573</span>
<span id="574">574</span>
<span id="575">575</span>
<span id="576">576</span>
<span id="577">577</span>
<span id="578">578</span>
<span id="579">579</span>
<span id="580">580</span>
<span id="581">581</span>
<span id="582">582</span>
<span id="583">583</span>
<span id="584">584</span>
<span id="585">585</span>
<span id="586">586</span>
<span id="587">587</span>
<span id="588">588</span>
<span id="589">589</span>
<span id="590">590</span>
<span id="591">591</span>
<span id="592">592</span>
<span id="593">593</span>
<span id="594">594</span>
<span id="595">595</span>
<span id="596">596</span>
<span id="597">597</span>
<span id="598">598</span>
<span id="599">599</span>
<span id="600">600</span>
<span id="601">601</span>
<span id="602">602</span>
<span id="603">603</span>
<span id="604">604</span>
<span id="605">605</span>
<span id="606">606</span>
<span id="607">607</span>
<span id="608">608</span>
<span id="609">609</span>
<span id="610">610</span>
<span id="611">611</span>
<span id="612">612</span>
<span id="613">613</span>
<span id="614">614</span>
<span id="615">615</span>
<span id="616">616</span>
<span id="617">617</span>
<span id="618">618</span>
<span id="619">619</span>
<span id="620">620</span>
<span id="621">621</span>
</pre><pre class="rust"><code><span class="doccomment">//! Callsites represent the source locations from which spans or events
//! originate.
//!
//! # What Are Callsites?
//!
//! Every span or event in `tracing` is associated with a [`Callsite`]. A
//! callsite is a small `static` value that is responsible for the following:
//!
//! * Storing the span or event&#39;s [`Metadata`],
//! * Uniquely [identifying](Identifier) the span or event definition,
//! * Caching the subscriber&#39;s [`Interest`][^1] in that span or event, to avoid
//! re-evaluating filters,
//! * Storing a [`Registration`] that allows the callsite to be part of a global
//! list of all callsites in the program.
//!
//! # Registering Callsites
//!
//! When a span or event is recorded for the first time, its callsite
//! [`register`]s itself with the global callsite registry. Registering a
//! callsite calls the [`Subscriber::register_callsite`][`register_callsite`]
//! method with that callsite&#39;s [`Metadata`] on every currently active
//! subscriber. This serves two primary purposes: informing subscribers of the
//! callsite&#39;s existence, and performing static filtering.
//!
//! ## Callsite Existence
//!
//! If a [`Subscriber`] implementation wishes to allocate storage for each
//! unique span/event location in the program, or pre-compute some value
//! that will be used to record that span or event in the future, it can
//! do so in its [`register_callsite`] method.
//!
//! ## Performing Static Filtering
//!
//! The [`register_callsite`] method returns an [`Interest`] value,
//! which indicates that the subscriber either [always] wishes to record
//! that span or event, [sometimes] wishes to record it based on a
//! dynamic filter evaluation, or [never] wishes to record it.
//!
//! When registering a new callsite, the [`Interest`]s returned by every
//! currently active subscriber are combined, and the result is stored at
//! each callsite. This way, when the span or event occurs in the
//! future, the cached [`Interest`] value can be checked efficiently
//! to determine if the span or event should be recorded, without
//! needing to perform expensive filtering (i.e. calling the
//! [`Subscriber::enabled`] method every time a span or event occurs).
//!
//! ### Rebuilding Cached Interest
//!
//! When a new [`Dispatch`] is created (i.e. a new subscriber becomes
//! active), any previously cached [`Interest`] values are re-evaluated
//! for all callsites in the program. This way, if the new subscriber
//! will enable a callsite that was not previously enabled, the
//! [`Interest`] in that callsite is updated. Similarly, when a
//! subscriber is dropped, the interest cache is also re-evaluated, so
//! that any callsites enabled only by that subscriber are disabled.
//!
//! In addition, the [`rebuild_interest_cache`] function in this module can be
//! used to manually invalidate all cached interest and re-register those
//! callsites. This function is useful in situations where a subscriber&#39;s
//! interest can change, but it does so relatively infrequently. The subscriber
//! may wish for its interest to be cached most of the time, and return
//! [`Interest::always`][always] or [`Interest::never`][never] in its
//! [`register_callsite`] method, so that its [`Subscriber::enabled`] method
//! doesn&#39;t need to be evaluated every time a span or event is recorded.
//! However, when the configuration changes, the subscriber can call
//! [`rebuild_interest_cache`] to re-evaluate the entire interest cache with its
//! new configuration. This is a relatively costly operation, but if the
//! configuration changes infrequently, it may be more efficient than calling
//! [`Subscriber::enabled`] frequently.
//!
//! # Implementing Callsites
//!
//! In most cases, instrumenting code using `tracing` should *not* require
//! implementing the [`Callsite`] trait directly. When using the [`tracing`
//! crate&#39;s macros][macros] or the [`#[instrument]` attribute][instrument], a
//! `Callsite` is automatically generated.
//!
//! However, code which provides alternative forms of `tracing` instrumentation
//! may need to interact with the callsite system directly. If
//! instrumentation-side code needs to produce a `Callsite` to emit spans or
//! events, the [`DefaultCallsite`] struct provided in this module is a
//! ready-made `Callsite` implementation that is suitable for most uses. When
//! possible, the use of `DefaultCallsite` should be preferred over implementing
//! [`Callsite`] for user types, as `DefaultCallsite` may benefit from
//! additional performance optimizations.
//!
//! [^1]: Returned by the [`Subscriber::register_callsite`][`register_callsite`]
//! method.
//!
//! [`Metadata`]: crate::metadata::Metadata
//! [`Interest`]: crate::subscriber::Interest
//! [`Subscriber`]: crate::subscriber::Subscriber
//! [`register_callsite`]: crate::subscriber::Subscriber::register_callsite
//! [`Subscriber::enabled`]: crate::subscriber::Subscriber::enabled
//! [always]: crate::subscriber::Interest::always
//! [sometimes]: crate::subscriber::Interest::sometimes
//! [never]: crate::subscriber::Interest::never
//! [`Dispatch`]: crate::dispatch::Dispatch
//! [macros]: https://docs.rs/tracing/latest/tracing/#macros
//! [instrument]: https://docs.rs/tracing/latest/tracing/attr.instrument.html
</span><span class="kw">use </span><span class="kw">crate</span>::stdlib::{
any::TypeId,
fmt,
hash::{Hash, Hasher},
ptr,
sync::{
atomic::{AtomicBool, AtomicPtr, AtomicU8, Ordering},
Mutex,
},
vec::Vec,
};
<span class="kw">use crate</span>::{
dispatcher::Dispatch,
lazy::Lazy,
metadata::{LevelFilter, Metadata},
subscriber::Interest,
};
<span class="kw">use </span><span class="self">self</span>::dispatchers::Dispatchers;
<span class="doccomment">/// Trait implemented by callsites.
///
/// These functions are only intended to be called by the callsite registry, which
/// correctly handles determining the common interest between all subscribers.
///
/// See the [module-level documentation](crate::callsite) for details on
/// callsites.
</span><span class="kw">pub trait </span>Callsite: Sync {
<span class="doccomment">/// Sets the [`Interest`] for this callsite.
///
/// See the [documentation on callsite interest caching][cache-docs] for
/// details.
///
/// [`Interest`]: super::subscriber::Interest
/// [cache-docs]: crate::callsite#performing-static-filtering
</span><span class="kw">fn </span>set_interest(<span class="kw-2">&amp;</span><span class="self">self</span>, interest: Interest);
<span class="doccomment">/// Returns the [metadata] associated with the callsite.
///
/// &lt;div class=&quot;example-wrap&quot; style=&quot;display:inline-block&quot;&gt;
/// &lt;pre class=&quot;ignore&quot; style=&quot;white-space:normal;font:inherit;&quot;&gt;
///
/// **Note:** Implementations of this method should not produce [`Metadata`]
/// that share the same callsite [`Identifier`] but otherwise differ in any
/// way (e.g., have different `name`s).
///
/// &lt;/pre&gt;&lt;/div&gt;
///
/// [metadata]: super::metadata::Metadata
</span><span class="kw">fn </span>metadata(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>Metadata&lt;<span class="lifetime">&#39;_</span>&gt;;
<span class="doccomment">/// This method is an *internal implementation detail* of `tracing-core`. It
/// is *not* intended to be called or overridden from downstream code.
///
/// The `Private` type can only be constructed from within `tracing-core`.
/// Because this method takes a `Private` as an argument, it cannot be
/// called from (safe) code external to `tracing-core`. Because it must
/// *return* a `Private`, the only valid implementation possible outside of
/// `tracing-core` would have to always unconditionally panic.
///
/// THIS IS BY DESIGN. There is currently no valid reason for code outside
/// of `tracing-core` to override this method.
</span><span class="comment">// TODO(eliza): this could be used to implement a public downcasting API
// for `&amp;dyn Callsite`s in the future.
</span><span class="attribute">#[doc(hidden)]
#[inline]
</span><span class="kw">fn </span>private_type_id(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="kw">_</span>: private::Private&lt;()&gt;) -&gt; private::Private&lt;TypeId&gt;
<span class="kw">where
</span><span class="self">Self</span>: <span class="lifetime">&#39;static</span>,
{
private::Private(TypeId::of::&lt;<span class="self">Self</span>&gt;())
}
}
<span class="doccomment">/// Uniquely identifies a [`Callsite`]
///
/// Two `Identifier`s are equal if they both refer to the same callsite.
///
/// [`Callsite`]: super::callsite::Callsite
</span><span class="attribute">#[derive(Clone)]
</span><span class="kw">pub struct </span>Identifier(
<span class="doccomment">/// **Warning**: The fields on this type are currently `pub` because it must
/// be able to be constructed statically by macros. However, when `const
/// fn`s are available on stable Rust, this will no longer be necessary.
/// Thus, these fields are *not* considered stable public API, and they may
/// change warning. Do not rely on any fields on `Identifier`. When
/// constructing new `Identifier`s, use the `identify_callsite!` macro
/// instead.
</span><span class="attribute">#[doc(hidden)]
</span><span class="kw">pub </span><span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span><span class="kw">dyn </span>Callsite,
);
<span class="doccomment">/// A default [`Callsite`] implementation.
</span><span class="attribute">#[derive(Debug)]
</span><span class="kw">pub struct </span>DefaultCallsite {
interest: AtomicU8,
registration: AtomicU8,
meta: <span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span>Metadata&lt;<span class="lifetime">&#39;static</span>&gt;,
next: AtomicPtr&lt;<span class="self">Self</span>&gt;,
}
<span class="doccomment">/// Clear and reregister interest on every [`Callsite`]
///
/// This function is intended for runtime reconfiguration of filters on traces
/// when the filter recalculation is much less frequent than trace events are.
/// The alternative is to have the [`Subscriber`] that supports runtime
/// reconfiguration of filters always return [`Interest::sometimes()`] so that
/// [`enabled`] is evaluated for every event.
///
/// This function will also re-compute the global maximum level as determined by
/// the [`max_level_hint`] method. If a [`Subscriber`]
/// implementation changes the value returned by its `max_level_hint`
/// implementation at runtime, then it **must** call this function after that
/// value changes, in order for the change to be reflected.
///
/// See the [documentation on callsite interest caching][cache-docs] for
/// additional information on this function&#39;s usage.
///
/// [`max_level_hint`]: super::subscriber::Subscriber::max_level_hint
/// [`Callsite`]: super::callsite::Callsite
/// [`enabled`]: super::subscriber::Subscriber#tymethod.enabled
/// [`Interest::sometimes()`]: super::subscriber::Interest::sometimes
/// [`Subscriber`]: super::subscriber::Subscriber
/// [cache-docs]: crate::callsite#rebuilding-cached-interest
</span><span class="kw">pub fn </span>rebuild_interest_cache() {
CALLSITES.rebuild_interest(DISPATCHERS.rebuilder());
}
<span class="doccomment">/// Register a new [`Callsite`] with the global registry.
///
/// This should be called once per callsite after the callsite has been
/// constructed.
///
/// See the [documentation on callsite registration][reg-docs] for details
/// on the global callsite registry.
///
/// [`Callsite`]: crate::callsite::Callsite
/// [reg-docs]: crate::callsite#registering-callsites
</span><span class="kw">pub fn </span>register(callsite: <span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span><span class="kw">dyn </span>Callsite) {
rebuild_callsite_interest(callsite, <span class="kw-2">&amp;</span>DISPATCHERS.rebuilder());
<span class="comment">// Is this a `DefaultCallsite`? If so, use the fancy linked list!
</span><span class="kw">if </span>callsite.private_type_id(private::Private(())).<span class="number">0 </span>== TypeId::of::&lt;DefaultCallsite&gt;() {
<span class="kw">let </span>callsite = <span class="kw">unsafe </span>{
<span class="comment">// Safety: the pointer cast is safe because the type id of the
// provided callsite matches that of the target type for the cast
// (`DefaultCallsite`). Because user implementations of `Callsite`
// cannot override `private_type_id`, we can trust that the callsite
// is not lying about its type ID.
</span><span class="kw-2">&amp;*</span>(callsite <span class="kw">as </span><span class="kw-2">*const </span><span class="kw">dyn </span>Callsite <span class="kw">as </span><span class="kw-2">*const </span>DefaultCallsite)
};
CALLSITES.push_default(callsite);
<span class="kw">return</span>;
}
CALLSITES.push_dyn(callsite);
}
<span class="kw">static </span>CALLSITES: Callsites = Callsites {
list_head: AtomicPtr::new(ptr::null_mut()),
has_locked_callsites: AtomicBool::new(<span class="bool-val">false</span>),
};
<span class="kw">static </span>DISPATCHERS: Dispatchers = Dispatchers::new();
<span class="kw">static </span>LOCKED_CALLSITES: Lazy&lt;Mutex&lt;Vec&lt;<span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span><span class="kw">dyn </span>Callsite&gt;&gt;&gt; = Lazy::new(Default::default);
<span class="kw">struct </span>Callsites {
list_head: AtomicPtr&lt;DefaultCallsite&gt;,
has_locked_callsites: AtomicBool,
}
<span class="comment">// === impl DefaultCallsite ===
</span><span class="kw">impl </span>DefaultCallsite {
<span class="kw">const </span>UNREGISTERED: u8 = <span class="number">0</span>;
<span class="kw">const </span>REGISTERING: u8 = <span class="number">1</span>;
<span class="kw">const </span>REGISTERED: u8 = <span class="number">2</span>;
<span class="kw">const </span>INTEREST_NEVER: u8 = <span class="number">0</span>;
<span class="kw">const </span>INTEREST_SOMETIMES: u8 = <span class="number">1</span>;
<span class="kw">const </span>INTEREST_ALWAYS: u8 = <span class="number">2</span>;
<span class="doccomment">/// Returns a new `DefaultCallsite` with the specified `Metadata`.
</span><span class="kw">pub const fn </span>new(meta: <span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span>Metadata&lt;<span class="lifetime">&#39;static</span>&gt;) -&gt; <span class="self">Self </span>{
<span class="self">Self </span>{
interest: AtomicU8::new(<span class="number">0xFF</span>),
meta,
next: AtomicPtr::new(ptr::null_mut()),
registration: AtomicU8::new(<span class="self">Self</span>::UNREGISTERED),
}
}
<span class="doccomment">/// Registers this callsite with the global callsite registry.
///
/// If the callsite is already registered, this does nothing. When using
/// [`DefaultCallsite`], this method should be preferred over
/// [`tracing_core::callsite::register`], as it ensures that the callsite is
/// only registered a single time.
///
/// Other callsite implementations will generally ensure that
/// callsites are not re-registered through another mechanism.
///
/// See the [documentation on callsite registration][reg-docs] for details
/// on the global callsite registry.
///
/// [`Callsite`]: crate::callsite::Callsite
/// [reg-docs]: crate::callsite#registering-callsites
</span><span class="attribute">#[inline(never)]
</span><span class="comment">// This only happens once (or if the cached interest value was corrupted).
</span><span class="attribute">#[cold]
</span><span class="kw">pub fn </span>register(<span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span><span class="self">self</span>) -&gt; Interest {
<span class="comment">// Attempt to advance the registration state to `REGISTERING`...
</span><span class="kw">match </span><span class="self">self</span>.registration.compare_exchange(
<span class="self">Self</span>::UNREGISTERED,
<span class="self">Self</span>::REGISTERING,
Ordering::AcqRel,
Ordering::Acquire,
) {
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) =&gt; {
<span class="comment">// Okay, we advanced the state, try to register the callsite.
</span>rebuild_callsite_interest(<span class="self">self</span>, <span class="kw-2">&amp;</span>DISPATCHERS.rebuilder());
CALLSITES.push_default(<span class="self">self</span>);
<span class="self">self</span>.registration.store(<span class="self">Self</span>::REGISTERED, Ordering::Release);
}
<span class="comment">// Great, the callsite is already registered! Just load its
// previous cached interest.
</span><span class="prelude-val">Err</span>(<span class="self">Self</span>::REGISTERED) =&gt; {}
<span class="comment">// Someone else is registering...
</span><span class="prelude-val">Err</span>(_state) =&gt; {
<span class="macro">debug_assert_eq!</span>(
_state,
<span class="self">Self</span>::REGISTERING,
<span class="string">&quot;weird callsite registration state&quot;
</span>);
<span class="comment">// Just hit `enabled` this time.
</span><span class="kw">return </span>Interest::sometimes();
}
}
<span class="kw">match </span><span class="self">self</span>.interest.load(Ordering::Relaxed) {
<span class="self">Self</span>::INTEREST_NEVER =&gt; Interest::never(),
<span class="self">Self</span>::INTEREST_ALWAYS =&gt; Interest::always(),
<span class="kw">_ </span>=&gt; Interest::sometimes(),
}
}
<span class="doccomment">/// Returns the callsite&#39;s cached `Interest`, or registers it for the
/// first time if it has not yet been registered.
</span><span class="attribute">#[inline]
</span><span class="kw">pub fn </span>interest(<span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span><span class="self">self</span>) -&gt; Interest {
<span class="kw">match </span><span class="self">self</span>.interest.load(Ordering::Relaxed) {
<span class="self">Self</span>::INTEREST_NEVER =&gt; Interest::never(),
<span class="self">Self</span>::INTEREST_SOMETIMES =&gt; Interest::sometimes(),
<span class="self">Self</span>::INTEREST_ALWAYS =&gt; Interest::always(),
<span class="kw">_ </span>=&gt; <span class="self">self</span>.register(),
}
}
}
<span class="kw">impl </span>Callsite <span class="kw">for </span>DefaultCallsite {
<span class="kw">fn </span>set_interest(<span class="kw-2">&amp;</span><span class="self">self</span>, interest: Interest) {
<span class="kw">let </span>interest = <span class="kw">match </span>() {
<span class="kw">_ if </span>interest.is_never() =&gt; <span class="self">Self</span>::INTEREST_NEVER,
<span class="kw">_ if </span>interest.is_always() =&gt; <span class="self">Self</span>::INTEREST_ALWAYS,
<span class="kw">_ </span>=&gt; <span class="self">Self</span>::INTEREST_SOMETIMES,
};
<span class="self">self</span>.interest.store(interest, Ordering::SeqCst);
}
<span class="attribute">#[inline(always)]
</span><span class="kw">fn </span>metadata(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>Metadata&lt;<span class="lifetime">&#39;static</span>&gt; {
<span class="self">self</span>.meta
}
}
<span class="comment">// ===== impl Identifier =====
</span><span class="kw">impl </span>PartialEq <span class="kw">for </span>Identifier {
<span class="kw">fn </span>eq(<span class="kw-2">&amp;</span><span class="self">self</span>, other: <span class="kw-2">&amp;</span>Identifier) -&gt; bool {
core::ptr::eq(
<span class="self">self</span>.<span class="number">0 </span><span class="kw">as </span><span class="kw-2">*const </span><span class="kw">_ as </span><span class="kw-2">*const </span>(),
other.<span class="number">0 </span><span class="kw">as </span><span class="kw-2">*const </span><span class="kw">_ as </span><span class="kw-2">*const </span>(),
)
}
}
<span class="kw">impl </span>Eq <span class="kw">for </span>Identifier {}
<span class="kw">impl </span>fmt::Debug <span class="kw">for </span>Identifier {
<span class="kw">fn </span>fmt(<span class="kw-2">&amp;</span><span class="self">self</span>, f: <span class="kw-2">&amp;mut </span>fmt::Formatter&lt;<span class="lifetime">&#39;_</span>&gt;) -&gt; fmt::Result {
<span class="macro">write!</span>(f, <span class="string">&quot;Identifier({:p})&quot;</span>, <span class="self">self</span>.<span class="number">0</span>)
}
}
<span class="kw">impl </span>Hash <span class="kw">for </span>Identifier {
<span class="kw">fn </span>hash&lt;H&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>H)
<span class="kw">where
</span>H: Hasher,
{
(<span class="self">self</span>.<span class="number">0 </span><span class="kw">as </span><span class="kw-2">*const </span><span class="kw">dyn </span>Callsite).hash(state)
}
}
<span class="comment">// === impl Callsites ===
</span><span class="kw">impl </span>Callsites {
<span class="doccomment">/// Rebuild `Interest`s for all callsites in the registry.
///
/// This also re-computes the max level hint.
</span><span class="kw">fn </span>rebuild_interest(<span class="kw-2">&amp;</span><span class="self">self</span>, dispatchers: dispatchers::Rebuilder&lt;<span class="lifetime">&#39;_</span>&gt;) {
<span class="kw">let </span><span class="kw-2">mut </span>max_level = LevelFilter::OFF;
dispatchers.for_each(|dispatch| {
<span class="comment">// If the subscriber did not provide a max level hint, assume
// that it may enable every level.
</span><span class="kw">let </span>level_hint = dispatch.max_level_hint().unwrap_or(LevelFilter::TRACE);
<span class="kw">if </span>level_hint &gt; max_level {
max_level = level_hint;
}
});
<span class="self">self</span>.for_each(|callsite| {
rebuild_callsite_interest(callsite, <span class="kw-2">&amp;</span>dispatchers);
});
LevelFilter::set_max(max_level);
}
<span class="doccomment">/// Push a `dyn Callsite` trait object to the callsite registry.
///
/// This will attempt to lock the callsites vector.
</span><span class="kw">fn </span>push_dyn(<span class="kw-2">&amp;</span><span class="self">self</span>, callsite: <span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span><span class="kw">dyn </span>Callsite) {
<span class="kw">let </span><span class="kw-2">mut </span>lock = LOCKED_CALLSITES.lock().unwrap();
<span class="self">self</span>.has_locked_callsites.store(<span class="bool-val">true</span>, Ordering::Release);
lock.push(callsite);
}
<span class="doccomment">/// Push a `DefaultCallsite` to the callsite registry.
///
/// If we know the callsite being pushed is a `DefaultCallsite`, we can push
/// it to the linked list without having to acquire a lock.
</span><span class="kw">fn </span>push_default(<span class="kw-2">&amp;</span><span class="self">self</span>, callsite: <span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span>DefaultCallsite) {
<span class="kw">let </span><span class="kw-2">mut </span>head = <span class="self">self</span>.list_head.load(Ordering::Acquire);
<span class="kw">loop </span>{
callsite.next.store(head, Ordering::Release);
<span class="macro">assert_ne!</span>(
callsite <span class="kw">as </span><span class="kw-2">*const </span><span class="kw">_</span>, head,
<span class="string">&quot;Attempted to register a `DefaultCallsite` that already exists! \
This will cause an infinite loop when attempting to read from the \
callsite cache. This is likely a bug! You should only need to call \
`DefaultCallsite::register` once per `DefaultCallsite`.&quot;
</span>);
<span class="kw">match </span><span class="self">self</span>.list_head.compare_exchange(
head,
callsite <span class="kw">as </span><span class="kw-2">*const </span><span class="kw">_ as </span><span class="kw-2">*mut </span><span class="kw">_</span>,
Ordering::AcqRel,
Ordering::Acquire,
) {
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) =&gt; {
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(current) =&gt; head = current,
}
}
}
<span class="doccomment">/// Invokes the provided closure `f` with each callsite in the registry.
</span><span class="kw">fn </span>for_each(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="kw-2">mut </span>f: <span class="kw">impl </span>FnMut(<span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span><span class="kw">dyn </span>Callsite)) {
<span class="kw">let </span><span class="kw-2">mut </span>head = <span class="self">self</span>.list_head.load(Ordering::Acquire);
<span class="kw">while let </span><span class="prelude-val">Some</span>(cs) = <span class="kw">unsafe </span>{ head.as_ref() } {
f(cs);
head = cs.next.load(Ordering::Acquire);
}
<span class="kw">if </span><span class="self">self</span>.has_locked_callsites.load(Ordering::Acquire) {
<span class="kw">let </span>locked = LOCKED_CALLSITES.lock().unwrap();
<span class="kw">for </span><span class="kw-2">&amp;</span>cs <span class="kw">in </span>locked.iter() {
f(cs);
}
}
}
}
<span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>register_dispatch(dispatch: <span class="kw-2">&amp;</span>Dispatch) {
<span class="kw">let </span>dispatchers = DISPATCHERS.register_dispatch(dispatch);
dispatch.subscriber().on_register_dispatch(dispatch);
CALLSITES.rebuild_interest(dispatchers);
}
<span class="kw">fn </span>rebuild_callsite_interest(
callsite: <span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span><span class="kw">dyn </span>Callsite,
dispatchers: <span class="kw-2">&amp;</span>dispatchers::Rebuilder&lt;<span class="lifetime">&#39;_</span>&gt;,
) {
<span class="kw">let </span>meta = callsite.metadata();
<span class="kw">let </span><span class="kw-2">mut </span>interest = <span class="prelude-val">None</span>;
dispatchers.for_each(|dispatch| {
<span class="kw">let </span>this_interest = dispatch.register_callsite(meta);
interest = <span class="kw">match </span>interest.take() {
<span class="prelude-val">None </span>=&gt; <span class="prelude-val">Some</span>(this_interest),
<span class="prelude-val">Some</span>(that_interest) =&gt; <span class="prelude-val">Some</span>(that_interest.and(this_interest)),
}
});
<span class="kw">let </span>interest = interest.unwrap_or_else(Interest::never);
callsite.set_interest(interest)
}
<span class="kw">mod </span>private {
<span class="doccomment">/// Don&#39;t call this function, it&#39;s private.
</span><span class="attribute">#[allow(missing_debug_implementations)]
</span><span class="kw">pub struct </span>Private&lt;T&gt;(<span class="kw">pub</span>(<span class="kw">crate</span>) T);
}
<span class="attribute">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">mod </span>dispatchers {
<span class="kw">use crate</span>::{dispatcher, lazy::Lazy};
<span class="kw">use </span>std::sync::{
atomic::{AtomicBool, Ordering},
RwLock, RwLockReadGuard, RwLockWriteGuard,
};
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">struct </span>Dispatchers {
has_just_one: AtomicBool,
}
<span class="kw">static </span>LOCKED_DISPATCHERS: Lazy&lt;RwLock&lt;Vec&lt;dispatcher::Registrar&gt;&gt;&gt; =
Lazy::new(Default::default);
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">enum </span>Rebuilder&lt;<span class="lifetime">&#39;a</span>&gt; {
JustOne,
Read(RwLockReadGuard&lt;<span class="lifetime">&#39;a</span>, Vec&lt;dispatcher::Registrar&gt;&gt;),
Write(RwLockWriteGuard&lt;<span class="lifetime">&#39;a</span>, Vec&lt;dispatcher::Registrar&gt;&gt;),
}
<span class="kw">impl </span>Dispatchers {
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">const fn </span>new() -&gt; <span class="self">Self </span>{
<span class="self">Self </span>{
has_just_one: AtomicBool::new(<span class="bool-val">true</span>),
}
}
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>rebuilder(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; Rebuilder&lt;<span class="lifetime">&#39;_</span>&gt; {
<span class="kw">if </span><span class="self">self</span>.has_just_one.load(Ordering::SeqCst) {
<span class="kw">return </span>Rebuilder::JustOne;
}
Rebuilder::Read(LOCKED_DISPATCHERS.read().unwrap())
}
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>register_dispatch(<span class="kw-2">&amp;</span><span class="self">self</span>, dispatch: <span class="kw-2">&amp;</span>dispatcher::Dispatch) -&gt; Rebuilder&lt;<span class="lifetime">&#39;_</span>&gt; {
<span class="kw">let </span><span class="kw-2">mut </span>dispatchers = LOCKED_DISPATCHERS.write().unwrap();
dispatchers.retain(|d| d.upgrade().is_some());
dispatchers.push(dispatch.registrar());
<span class="self">self</span>.has_just_one
.store(dispatchers.len() &lt;= <span class="number">1</span>, Ordering::SeqCst);
Rebuilder::Write(dispatchers)
}
}
<span class="kw">impl </span>Rebuilder&lt;<span class="lifetime">&#39;_</span>&gt; {
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>for_each(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="kw-2">mut </span>f: <span class="kw">impl </span>FnMut(<span class="kw-2">&amp;</span>dispatcher::Dispatch)) {
<span class="kw">let </span>iter = <span class="kw">match </span><span class="self">self </span>{
Rebuilder::JustOne =&gt; {
dispatcher::get_default(f);
<span class="kw">return</span>;
}
Rebuilder::Read(vec) =&gt; vec.iter(),
Rebuilder::Write(vec) =&gt; vec.iter(),
};
iter.filter_map(dispatcher::Registrar::upgrade)
.for_each(|dispatch| f(<span class="kw-2">&amp;</span>dispatch))
}
}
}
<span class="attribute">#[cfg(not(feature = <span class="string">&quot;std&quot;</span>))]
</span><span class="kw">mod </span>dispatchers {
<span class="kw">use </span><span class="kw">crate</span>::dispatcher;
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">struct </span>Dispatchers(());
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">struct </span>Rebuilder&lt;<span class="lifetime">&#39;a</span>&gt;(<span class="prelude-ty">Option</span>&lt;<span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>dispatcher::Dispatch&gt;);
<span class="kw">impl </span>Dispatchers {
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">const fn </span>new() -&gt; <span class="self">Self </span>{
<span class="self">Self</span>(())
}
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>rebuilder(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; Rebuilder&lt;<span class="lifetime">&#39;_</span>&gt; {
Rebuilder(<span class="prelude-val">None</span>)
}
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>register_dispatch&lt;<span class="lifetime">&#39;dispatch</span>&gt;(
<span class="kw-2">&amp;</span><span class="self">self</span>,
dispatch: <span class="kw-2">&amp;</span><span class="lifetime">&#39;dispatch </span>dispatcher::Dispatch,
) -&gt; Rebuilder&lt;<span class="lifetime">&#39;dispatch</span>&gt; {
<span class="comment">// nop; on no_std, there can only ever be one dispatcher
</span>Rebuilder(<span class="prelude-val">Some</span>(dispatch))
}
}
<span class="kw">impl </span>Rebuilder&lt;<span class="lifetime">&#39;_</span>&gt; {
<span class="attribute">#[inline]
</span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>for_each(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="kw-2">mut </span>f: <span class="kw">impl </span>FnMut(<span class="kw-2">&amp;</span>dispatcher::Dispatch)) {
<span class="kw">if let </span><span class="prelude-val">Some</span>(dispatch) = <span class="self">self</span>.<span class="number">0 </span>{
<span class="comment">// we are rebuilding the interest cache because a new dispatcher
// is about to be set. on `no_std`, this should only happen
// once, because the new dispatcher will be the global default.
</span>f(dispatch)
} <span class="kw">else </span>{
<span class="comment">// otherwise, we are rebuilding the cache because the subscriber
// configuration changed, so use the global default.
// on no_std, there can only ever be one dispatcher
</span>dispatcher::get_default(f)
}
}
}
}
</code></pre></div>
</section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="tracing_core" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>