-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmacro.cfg_match.html
31 lines (30 loc) · 5.37 KB
/
macro.cfg_match.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
<!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 macro for defining `#[cfg]` match-like statements."><title>cfg_match in tracing::stdlib - 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 macro"><!--[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="#">cfg_<wbr>match</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tracing::<wbr>stdlib</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>::<wbr><a href="index.html">stdlib</a></span><h1>Macro <span class="macro">cfg_match</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="https://doc.rust-lang.org/1.85.0/src/core/macros/mod.rs.html#229">Source</a> </span></div><pre class="rust item-decl"><code>pub(crate) macro cfg_match {
(
$(cfg($initial_meta:meta) => { $($initial_tokens:tt)* })+ _ => {
$($extra_tokens:tt)* }
) => { ... },
($(cfg($extra_meta:meta) => { $($extra_tokens:tt)* })*) => { ... },
(@ __items($($_:meta,)*);) => { ... },
(@ __items($($no:meta,)*); (($($yes:meta)?) ($($tokens:tt)*)), $($rest:tt,)*) => { ... },
(@ __identity $($tokens:tt)*) => { ... },
}</code></pre><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>cfg_match</code> <a href="https://github.com/tokio-rs/tracing/issues/115585">#115585</a>)</span></div></span><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A macro for defining <code>#[cfg]</code> match-like statements.</p>
<p>It is similar to the <code>if/elif</code> C preprocessor macro by allowing definition of a cascade of
<code>#[cfg]</code> cases, emitting the implementation which matches first.</p>
<p>This allows you to conveniently provide a long list <code>#[cfg]</code>’d blocks of code
without having to rewrite each clause multiple times.</p>
<p>Trailing <code>_</code> wildcard match arms are <strong>optional</strong> and they indicate a fallback branch when
all previous declarations do not evaluate to true.</p>
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#![feature(cfg_match)]
</span><span class="macro">cfg_match!</span> {
cfg(unix) => {
<span class="kw">fn </span>foo() { <span class="comment">/* unix specific functionality */ </span>}
}
cfg(target_pointer_width = <span class="string">"32"</span>) => {
<span class="kw">fn </span>foo() { <span class="comment">/* non-unix, 32-bit functionality */ </span>}
}
<span class="kw">_ </span>=> {
<span class="kw">fn </span>foo() { <span class="comment">/* fallback implementation */ </span>}
}
}</code></pre></div>
</div></details></section></div></main></body></html>