Auto Generated Documentation
This commit is contained in:
@@ -1,86 +1,76 @@
|
||||
<!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="Formatting macro for constructing `Ident`s."><meta name="keywords" content="rust, rustlang, rust-lang, format_ident"><title>format_ident in quote - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
|
||||
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
|
||||
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></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="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../quote/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class="location"><a href="index.html">quote</a></p><div id="sidebar-vars" data-name="format_ident" data-ty="macro" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
|
||||
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Macro <a href="index.html">quote</a>::<wbr><a class="macro" href="">format_ident</a><button id="copy-path" onclick="copy_path(this)">⎘</button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../src/quote/format.rs.html#110-124" title="goto source code">[src]</a></span></h1><div class="docblock type-decl"><div class="example-wrap"><pre class="rust macro">
|
||||
<span class="macro">macro_rules!</span> <span class="ident">format_ident</span> {
|
||||
(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">fmt</span>:<span class="ident">expr</span>) <span class="op">=</span><span class="op">></span> { ... };
|
||||
(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">fmt</span>:<span class="ident">expr</span>, $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">rest</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>) <span class="op">=</span><span class="op">></span> { ... };
|
||||
}</pre></div>
|
||||
</div><div class="docblock"><p>Formatting macro for constructing <code>Ident</code>s.</p>
|
||||
<!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="Formatting macro for constructing `Ident`s."><title>format_ident in quote - 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="quote" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.1 (4eb161250 2025-03-15)" data-channel="1.85.1" 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></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../quote/index.html">quote</a><span class="version">1.0.40</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">format_<wbr>ident</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#syntax" title="Syntax">Syntax</a></li><li><a href="#identfragment" title="IdentFragment">IdentFragment</a></li><li><a href="#hygiene" title="Hygiene">Hygiene</a></li><li><a href="#panics" title="Panics">Panics</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate quote</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">quote</a></span><h1>Macro <span class="macro">format_ident</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/quote/format.rs.html#111-125">Source</a> </span></div><pre class="rust item-decl"><code>macro_rules! format_ident {
|
||||
($fmt:expr) => { ... };
|
||||
($fmt:expr, $($rest:tt)*) => { ... };
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Formatting macro for constructing <code>Ident</code>s.</p>
|
||||
<br>
|
||||
<h1 id="syntax" class="section-header"><a href="#syntax">Syntax</a></h1>
|
||||
<p>Syntax is copied from the <a href="https://doc.rust-lang.org/nightly/alloc/macro.format.html" title="format!"><code>format!</code></a> macro, supporting both positional and
|
||||
<h2 id="syntax"><a class="doc-anchor" href="#syntax">§</a>Syntax</h2>
|
||||
<p>Syntax is copied from the <a href="https://doc.rust-lang.org/1.85.1/alloc/macro.format.html" title="macro alloc::format"><code>format!</code></a> macro, supporting both positional and
|
||||
named arguments.</p>
|
||||
<p>Only a limited set of formatting traits are supported. The current mapping
|
||||
of format types to traits is:</p>
|
||||
<ul>
|
||||
<li><code>{}</code> ⇒ [<code>IdentFragment</code>]</li>
|
||||
<li><code>{:o}</code> ⇒ <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Octal.html"><code>Octal</code></a></li>
|
||||
<li><code>{:x}</code> ⇒ <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.LowerHex.html"><code>LowerHex</code></a></li>
|
||||
<li><code>{:X}</code> ⇒ <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.UpperHex.html"><code>UpperHex</code></a></li>
|
||||
<li><code>{:b}</code> ⇒ <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Binary.html"><code>Binary</code></a></li>
|
||||
<li><code>{}</code> ⇒ <a href="trait.IdentFragment.html" title="trait quote::IdentFragment"><code>IdentFragment</code></a></li>
|
||||
<li><code>{:o}</code> ⇒ <a href="https://doc.rust-lang.org/1.85.1/core/fmt/trait.Octal.html" title="trait core::fmt::Octal"><code>Octal</code></a></li>
|
||||
<li><code>{:x}</code> ⇒ <a href="https://doc.rust-lang.org/1.85.1/core/fmt/trait.LowerHex.html" title="trait core::fmt::LowerHex"><code>LowerHex</code></a></li>
|
||||
<li><code>{:X}</code> ⇒ <a href="https://doc.rust-lang.org/1.85.1/core/fmt/trait.UpperHex.html" title="trait core::fmt::UpperHex"><code>UpperHex</code></a></li>
|
||||
<li><code>{:b}</code> ⇒ <a href="https://doc.rust-lang.org/1.85.1/core/fmt/trait.Binary.html" title="trait core::fmt::Binary"><code>Binary</code></a></li>
|
||||
</ul>
|
||||
<p>See <a href="https://doc.rust-lang.org/nightly/alloc/fmt/index.html" title="std::fmt"><code>std::fmt</code></a> for more information.</p>
|
||||
<p>See <a href="https://doc.rust-lang.org/1.85.1/alloc/fmt/index.html" title="mod alloc::fmt"><code>std::fmt</code></a> for more information.</p>
|
||||
<br>
|
||||
<h1 id="identfragment" class="section-header"><a href="#identfragment">IdentFragment</a></h1>
|
||||
<p>Unlike <code>format!</code>, this macro uses the [<code>IdentFragment</code>] formatting trait by
|
||||
<h2 id="identfragment"><a class="doc-anchor" href="#identfragment">§</a>IdentFragment</h2>
|
||||
<p>Unlike <code>format!</code>, this macro uses the <a href="trait.IdentFragment.html" title="trait quote::IdentFragment"><code>IdentFragment</code></a> formatting trait by
|
||||
default. This trait is like <code>Display</code>, with a few differences:</p>
|
||||
<ul>
|
||||
<li><code>IdentFragment</code> is only implemented for a limited set of types, such as
|
||||
unsigned integers and strings.</li>
|
||||
<li><a href="../proc_macro2/struct.Ident.html"><code>Ident</code></a> arguments will have their <code>r#</code> prefixes stripped, if present.</li>
|
||||
<li><a href="../proc_macro2/struct.Ident.html" title="struct proc_macro2::Ident"><code>Ident</code></a> arguments will have their <code>r#</code> prefixes stripped, if present.</li>
|
||||
</ul>
|
||||
<br>
|
||||
<h1 id="hygiene" class="section-header"><a href="#hygiene">Hygiene</a></h1>
|
||||
<p>The <a href="../proc_macro2/struct.Span.html"><code>Span</code></a> of the first <code>Ident</code> argument is used as the span of the final
|
||||
identifier, falling back to <a href="../proc_macro2/struct.Span.html#method.call_site"><code>Span::call_site</code></a> when no identifiers are
|
||||
<h2 id="hygiene"><a class="doc-anchor" href="#hygiene">§</a>Hygiene</h2>
|
||||
<p>The <a href="../proc_macro2/struct.Span.html" title="struct proc_macro2::Span"><code>Span</code></a> of the first <code>Ident</code> argument is used as the span of the final
|
||||
identifier, falling back to <a href="../proc_macro2/struct.Span.html#method.call_site" title="associated function proc_macro2::Span::call_site"><code>Span::call_site</code></a> when no identifiers are
|
||||
provided.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="comment">// If `ident` is an Ident, the span of `my_ident` will be inherited from it.</span>
|
||||
<span class="kw">let</span> <span class="ident">my_ident</span> <span class="op">=</span> <span class="macro">format_ident!</span>(<span class="string">"My{}{}"</span>, <span class="ident">ident</span>, <span class="string">"IsCool"</span>);
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">my_ident</span>, <span class="string">"MyIdentIsCool"</span>);</pre></div>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// If `ident` is an Ident, the span of `my_ident` will be inherited from it.
|
||||
</span><span class="kw">let </span>my_ident = <span class="macro">format_ident!</span>(<span class="string">"My{}{}"</span>, ident, <span class="string">"IsCool"</span>);
|
||||
<span class="macro">assert_eq!</span>(my_ident, <span class="string">"MyIdentIsCool"</span>);</code></pre></div>
|
||||
<p>Alternatively, the span can be overridden by passing the <code>span</code> named
|
||||
argument.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">let</span> <span class="ident">my_span</span> <span class="op">=</span> <span class="comment">/* ... */</span>;
|
||||
<span class="macro">format_ident!</span>(<span class="string">"MyIdent"</span>, <span class="ident">span</span> <span class="op">=</span> <span class="ident">my_span</span>);</pre></div>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>my_span = <span class="comment">/* ... */</span>;
|
||||
<span class="macro">format_ident!</span>(<span class="string">"MyIdent"</span>, span = my_span);</code></pre></div>
|
||||
<p><br></p>
|
||||
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This method will panic if the resulting formatted string is not a valid
|
||||
identifier.</p>
|
||||
<br>
|
||||
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>Composing raw and non-raw identifiers:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">let</span> <span class="ident">my_ident</span> <span class="op">=</span> <span class="macro">format_ident!</span>(<span class="string">"My{}"</span>, <span class="string">"Ident"</span>);
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">my_ident</span>, <span class="string">"MyIdent"</span>);
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>my_ident = <span class="macro">format_ident!</span>(<span class="string">"My{}"</span>, <span class="string">"Ident"</span>);
|
||||
<span class="macro">assert_eq!</span>(my_ident, <span class="string">"MyIdent"</span>);
|
||||
|
||||
<span class="kw">let</span> <span class="ident">raw</span> <span class="op">=</span> <span class="macro">format_ident!</span>(<span class="string">"r#Raw"</span>);
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">raw</span>, <span class="string">"r#Raw"</span>);
|
||||
<span class="kw">let </span>raw = <span class="macro">format_ident!</span>(<span class="string">"r#Raw"</span>);
|
||||
<span class="macro">assert_eq!</span>(raw, <span class="string">"r#Raw"</span>);
|
||||
|
||||
<span class="kw">let</span> <span class="ident">my_ident_raw</span> <span class="op">=</span> <span class="macro">format_ident!</span>(<span class="string">"{}Is{}"</span>, <span class="ident">my_ident</span>, <span class="ident">raw</span>);
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">my_ident_raw</span>, <span class="string">"MyIdentIsRaw"</span>);</pre></div>
|
||||
<span class="kw">let </span>my_ident_raw = <span class="macro">format_ident!</span>(<span class="string">"{}Is{}"</span>, my_ident, raw);
|
||||
<span class="macro">assert_eq!</span>(my_ident_raw, <span class="string">"MyIdentIsRaw"</span>);</code></pre></div>
|
||||
<p>Integer formatting options:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">let</span> <span class="ident">num</span>: <span class="ident">u32</span> <span class="op">=</span> <span class="number">10</span>;
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>num: u32 = <span class="number">10</span>;
|
||||
|
||||
<span class="kw">let</span> <span class="ident">decimal</span> <span class="op">=</span> <span class="macro">format_ident!</span>(<span class="string">"Id_{}"</span>, <span class="ident">num</span>);
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">decimal</span>, <span class="string">"Id_10"</span>);
|
||||
<span class="kw">let </span>decimal = <span class="macro">format_ident!</span>(<span class="string">"Id_{}"</span>, num);
|
||||
<span class="macro">assert_eq!</span>(decimal, <span class="string">"Id_10"</span>);
|
||||
|
||||
<span class="kw">let</span> <span class="ident">octal</span> <span class="op">=</span> <span class="macro">format_ident!</span>(<span class="string">"Id_{:o}"</span>, <span class="ident">num</span>);
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">octal</span>, <span class="string">"Id_12"</span>);
|
||||
<span class="kw">let </span>octal = <span class="macro">format_ident!</span>(<span class="string">"Id_{:o}"</span>, num);
|
||||
<span class="macro">assert_eq!</span>(octal, <span class="string">"Id_12"</span>);
|
||||
|
||||
<span class="kw">let</span> <span class="ident">binary</span> <span class="op">=</span> <span class="macro">format_ident!</span>(<span class="string">"Id_{:b}"</span>, <span class="ident">num</span>);
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">binary</span>, <span class="string">"Id_1010"</span>);
|
||||
<span class="kw">let </span>binary = <span class="macro">format_ident!</span>(<span class="string">"Id_{:b}"</span>, num);
|
||||
<span class="macro">assert_eq!</span>(binary, <span class="string">"Id_1010"</span>);
|
||||
|
||||
<span class="kw">let</span> <span class="ident">lower_hex</span> <span class="op">=</span> <span class="macro">format_ident!</span>(<span class="string">"Id_{:x}"</span>, <span class="ident">num</span>);
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">lower_hex</span>, <span class="string">"Id_a"</span>);
|
||||
<span class="kw">let </span>lower_hex = <span class="macro">format_ident!</span>(<span class="string">"Id_{:x}"</span>, num);
|
||||
<span class="macro">assert_eq!</span>(lower_hex, <span class="string">"Id_a"</span>);
|
||||
|
||||
<span class="kw">let</span> <span class="ident">upper_hex</span> <span class="op">=</span> <span class="macro">format_ident!</span>(<span class="string">"Id_{:X}"</span>, <span class="ident">num</span>);
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">upper_hex</span>, <span class="string">"Id_A"</span>);</pre></div>
|
||||
</div></section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="quote" data-search-index-js="../search-index.js" data-search-js="../search.js"></div>
|
||||
<script src="../main.js"></script></body></html>
|
||||
<span class="kw">let </span>upper_hex = <span class="macro">format_ident!</span>(<span class="string">"Id_{:X}"</span>, num);
|
||||
<span class="macro">assert_eq!</span>(upper_hex, <span class="string">"Id_A"</span>);</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
||||
Reference in New Issue
Block a user