mirror of
https://github.com/trussed-dev/flexiber.git
synced 2026-06-20 04:16:10 -07:00
deploy: b78a9a7a8538778ba390506f47f985ddacf0b0c3
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<!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="List of all items in this crate"><meta name="keywords" content="rust, rustlang, rust-lang"><title>List of all items in this crate</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><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 mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../synstructure/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Crate synstructure</p><div class="block version"><p>Version 0.12.4</p></div><a id="all-types" href="index.html"><p>Back to index</p></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><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" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><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>
|
||||
</span>
|
||||
<span class="in-band">List of all items</span></h1><h3 id="Structs">Structs</h3><ul class="structs docblock"><li><a href="struct.BindingInfo.html">BindingInfo</a></li><li><a href="struct.Structure.html">Structure</a></li><li><a href="struct.VariantAst.html">VariantAst</a></li><li><a href="struct.VariantInfo.html">VariantInfo</a></li></ul><h3 id="Enums">Enums</h3><ul class="enums docblock"><li><a href="enum.AddBounds.html">AddBounds</a></li><li><a href="enum.BindStyle.html">BindStyle</a></li></ul><h3 id="Traits">Traits</h3><ul class="traits docblock"><li><a href="trait.MacroResult.html">MacroResult</a></li></ul><h3 id="Macros">Macros</h3><ul class="macros docblock"><li><a href="macro.decl_attribute.html">decl_attribute</a></li><li><a href="macro.decl_derive.html">decl_derive</a></li><li><a href="macro.test_derive.html">test_derive</a></li></ul><h3 id="Functions">Functions</h3><ul class="functions docblock"><li><a href="fn.unpretty_print.html">unpretty_print</a></li></ul></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "synstructure";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,47 @@
|
||||
<!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="API documentation for the Rust `unpretty_print` fn in crate `synstructure`."><meta name="keywords" content="rust, rustlang, rust-lang, unpretty_print"><title>synstructure::unpretty_print - 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><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 fn"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../synstructure/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">synstructure</a></p><script>window.sidebarCurrent = {name: "unpretty_print", ty: "fn", relpath: ""};</script><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" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><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" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><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/synstructure/lib.rs.html#2355-2376" title="goto source code">[src]</a></span><span class="in-band">Function <a href="index.html">synstructure</a>::<wbr><a class="fn" href="">unpretty_print</a></span></h1><pre class="rust fn">pub fn unpretty_print<T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>>(ts: T) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></pre><div class="docblock"><p>Dumps an unpretty version of a tokenstream. Takes any type which implements
|
||||
<code>Display</code>.</p>
|
||||
<p>This is mostly useful for visualizing the output of a procedural macro, as
|
||||
it makes it marginally more readable. It is used in the implementation of
|
||||
<code>test_derive!</code> to unprettily print the output.</p>
|
||||
<h1 id="stability" class="section-header"><a href="#stability">Stability</a></h1>
|
||||
<p>The stability of the output of this function is not guaranteed. Do not
|
||||
assert that the output of this function does not change between minor
|
||||
versions.</p>
|
||||
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="macro">assert_eq</span><span class="macro">!</span>(
|
||||
<span class="ident">synstructure</span>::<span class="ident">unpretty_print</span>(<span class="macro">quote</span><span class="macro">!</span> {
|
||||
<span class="attribute">#[<span class="ident">allow</span>(<span class="ident">non_upper_case_globals</span>)]</span>
|
||||
<span class="kw">const</span> <span class="ident">_DERIVE_krate_Trait_FOR_A</span>: () <span class="op">=</span> {
|
||||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">krate</span>;
|
||||
<span class="kw">impl</span><span class="op"><</span><span class="ident">T</span>, <span class="ident">U</span><span class="op">></span> <span class="ident">krate</span>::<span class="ident">Trait</span> <span class="kw">for</span> <span class="ident">A</span><span class="op"><</span><span class="ident">T</span>, <span class="ident">U</span><span class="op">></span>
|
||||
<span class="kw">where</span>
|
||||
<span class="prelude-ty">Option</span><span class="op"><</span><span class="ident">U</span><span class="op">></span>: <span class="ident">krate</span>::<span class="ident">Trait</span>,
|
||||
<span class="ident">U</span>: <span class="ident">krate</span>::<span class="ident">Trait</span>
|
||||
{
|
||||
<span class="kw">fn</span> <span class="ident">a</span>() {}
|
||||
}
|
||||
};
|
||||
}),
|
||||
<span class="string">"# [
|
||||
allow (
|
||||
non_upper_case_globals )
|
||||
]
|
||||
const _DERIVE_krate_Trait_FOR_A : (
|
||||
)
|
||||
= {
|
||||
extern crate krate ;
|
||||
impl < T , U > krate :: Trait for A < T , U > where Option < U > : krate :: Trait , U : krate :: Trait {
|
||||
fn a (
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
"</span>
|
||||
)</pre></div>
|
||||
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "synstructure";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|
||||
@@ -0,0 +1,168 @@
|
||||
<!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="API documentation for the Rust `synstructure` crate."><meta name="keywords" content="rust, rustlang, rust-lang, synstructure"><title>synstructure - 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><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 mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../synstructure/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Crate synstructure</p><div class="block version"><p>Version 0.12.4</p></div><div class="sidebar-elems"><a id="all-types" href="all.html"><p>See all synstructure's items</p></a><div class="block items"><ul><li><a href="#macros">Macros</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li></ul></div><p class="location"></p><script>window.sidebarCurrent = {name: "synstructure", ty: "mod", relpath: "../"};</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" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><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" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><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/synstructure/lib.rs.html#1-2442" title="goto source code">[src]</a></span><span class="in-band">Crate <a class="mod" href="">synstructure</a></span></h1><div class="docblock"><p>This crate provides helper types for matching against enum variants, and
|
||||
extracting bindings to each of the fields in the deriving Struct or Enum in
|
||||
a generic way.</p>
|
||||
<p>If you are writing a <code>#[derive]</code> which needs to perform some operation on
|
||||
every field, then you have come to the right place!</p>
|
||||
<h1 id="example-walkfields" class="section-header"><a href="#example-walkfields">Example: <code>WalkFields</code></a></h1><h3 id="trait-implementation" class="section-header"><a href="#trait-implementation">Trait Implementation</a></h3>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">pub</span> <span class="kw">trait</span> <span class="ident">WalkFields</span>: <span class="ident">std</span>::<span class="ident">any</span>::<span class="ident">Any</span> {
|
||||
<span class="kw">fn</span> <span class="ident">walk_fields</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">walk</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">FnMut</span>(<span class="kw-2">&</span><span class="ident">WalkFields</span>));
|
||||
}
|
||||
<span class="kw">impl</span> <span class="ident">WalkFields</span> <span class="kw">for</span> <span class="ident">i32</span> {
|
||||
<span class="kw">fn</span> <span class="ident">walk_fields</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">_walk</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">FnMut</span>(<span class="kw-2">&</span><span class="ident">WalkFields</span>)) {}
|
||||
}</pre></div>
|
||||
<h3 id="custom-derive" class="section-header"><a href="#custom-derive">Custom Derive</a></h3>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">fn</span> <span class="ident">walkfields_derive</span>(<span class="ident">s</span>: <span class="ident">synstructure</span>::<span class="ident">Structure</span>) <span class="op">-</span><span class="op">></span> <span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span> {
|
||||
<span class="kw">let</span> <span class="ident">body</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">each</span>(<span class="op">|</span><span class="ident">bi</span><span class="op">|</span> <span class="macro">quote</span><span class="macro">!</span>{
|
||||
<span class="ident">walk</span>(#<span class="ident">bi</span>)
|
||||
});
|
||||
|
||||
<span class="ident">s</span>.<span class="ident">gen_impl</span>(<span class="macro">quote</span><span class="macro">!</span> {
|
||||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">synstructure_test_traits</span>;
|
||||
|
||||
<span class="ident">gen</span> <span class="kw">impl</span> <span class="ident">synstructure_test_traits</span>::<span class="ident">WalkFields</span> <span class="kw">for</span> @<span class="self">Self</span> {
|
||||
<span class="kw">fn</span> <span class="ident">walk_fields</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">walk</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">FnMut</span>(<span class="kw-2">&</span><span class="ident">synstructure_test_traits</span>::<span class="ident">WalkFields</span>)) {
|
||||
<span class="kw">match</span> <span class="kw-2">*</span><span class="self">self</span> { #<span class="ident">body</span> }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
<span class="ident">synstructure</span>::<span class="macro">decl_derive</span><span class="macro">!</span>([<span class="ident">WalkFields</span>] <span class="op">=</span><span class="op">></span> <span class="ident">walkfields_derive</span>);
|
||||
|
||||
<span class="comment">/*
|
||||
* Test Case
|
||||
*/</span>
|
||||
<span class="kw">fn</span> <span class="ident">main</span>() {
|
||||
<span class="ident">synstructure</span>::<span class="macro">test_derive</span><span class="macro">!</span> {
|
||||
<span class="ident">walkfields_derive</span> {
|
||||
<span class="kw">enum</span> <span class="ident">A</span><span class="op"><</span><span class="ident">T</span><span class="op">></span> {
|
||||
<span class="ident">B</span>(<span class="ident">i32</span>, <span class="ident">T</span>),
|
||||
<span class="ident">C</span>(<span class="ident">i32</span>),
|
||||
}
|
||||
}
|
||||
<span class="ident">expands</span> <span class="ident">to</span> {
|
||||
<span class="attribute">#[<span class="ident">allow</span>(<span class="ident">non_upper_case_globals</span>)]</span>
|
||||
<span class="kw">const</span> <span class="ident">_DERIVE_synstructure_test_traits_WalkFields_FOR_A</span>: () <span class="op">=</span> {
|
||||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">synstructure_test_traits</span>;
|
||||
<span class="kw">impl</span><span class="op"><</span><span class="ident">T</span><span class="op">></span> <span class="ident">synstructure_test_traits</span>::<span class="ident">WalkFields</span> <span class="kw">for</span> <span class="ident">A</span><span class="op"><</span><span class="ident">T</span><span class="op">></span>
|
||||
<span class="kw">where</span> <span class="ident">T</span>: <span class="ident">synstructure_test_traits</span>::<span class="ident">WalkFields</span>
|
||||
{
|
||||
<span class="kw">fn</span> <span class="ident">walk_fields</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">walk</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">FnMut</span>(<span class="kw-2">&</span><span class="ident">synstructure_test_traits</span>::<span class="ident">WalkFields</span>)) {
|
||||
<span class="kw">match</span> <span class="kw-2">*</span><span class="self">self</span> {
|
||||
<span class="ident">A</span>::<span class="ident">B</span>(<span class="kw-2">ref</span> <span class="ident">__binding_0</span>, <span class="kw-2">ref</span> <span class="ident">__binding_1</span>,) <span class="op">=</span><span class="op">></span> {
|
||||
{ <span class="ident">walk</span>(<span class="ident">__binding_0</span>) }
|
||||
{ <span class="ident">walk</span>(<span class="ident">__binding_1</span>) }
|
||||
}
|
||||
<span class="ident">A</span>::<span class="ident">C</span>(<span class="kw-2">ref</span> <span class="ident">__binding_0</span>,) <span class="op">=</span><span class="op">></span> {
|
||||
{ <span class="ident">walk</span>(<span class="ident">__binding_0</span>) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}</pre></div>
|
||||
<h1 id="example-interest" class="section-header"><a href="#example-interest">Example: <code>Interest</code></a></h1><h3 id="trait-implementation-1" class="section-header"><a href="#trait-implementation-1">Trait Implementation</a></h3>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">pub</span> <span class="kw">trait</span> <span class="ident">Interest</span> {
|
||||
<span class="kw">fn</span> <span class="ident">interesting</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">bool</span>;
|
||||
}
|
||||
<span class="kw">impl</span> <span class="ident">Interest</span> <span class="kw">for</span> <span class="ident">i32</span> {
|
||||
<span class="kw">fn</span> <span class="ident">interesting</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">bool</span> { <span class="kw-2">*</span><span class="self">self</span> <span class="op">></span> <span class="number">0</span> }
|
||||
}</pre></div>
|
||||
<h3 id="custom-derive-1" class="section-header"><a href="#custom-derive-1">Custom Derive</a></h3>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">fn</span> <span class="ident">interest_derive</span>(<span class="kw-2">mut</span> <span class="ident">s</span>: <span class="ident">synstructure</span>::<span class="ident">Structure</span>) <span class="op">-</span><span class="op">></span> <span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span> {
|
||||
<span class="kw">let</span> <span class="ident">body</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">fold</span>(<span class="bool-val">false</span>, <span class="op">|</span><span class="ident">acc</span>, <span class="ident">bi</span><span class="op">|</span> <span class="macro">quote</span><span class="macro">!</span>{
|
||||
#<span class="ident">acc</span> <span class="op">|</span><span class="op">|</span> <span class="ident">synstructure_test_traits</span>::<span class="ident">Interest</span>::<span class="ident">interesting</span>(#<span class="ident">bi</span>)
|
||||
});
|
||||
|
||||
<span class="ident">s</span>.<span class="ident">gen_impl</span>(<span class="macro">quote</span><span class="macro">!</span> {
|
||||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">synstructure_test_traits</span>;
|
||||
<span class="ident">gen</span> <span class="kw">impl</span> <span class="ident">synstructure_test_traits</span>::<span class="ident">Interest</span> <span class="kw">for</span> @<span class="self">Self</span> {
|
||||
<span class="kw">fn</span> <span class="ident">interesting</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">bool</span> {
|
||||
<span class="kw">match</span> <span class="kw-2">*</span><span class="self">self</span> {
|
||||
#<span class="ident">body</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
<span class="ident">synstructure</span>::<span class="macro">decl_derive</span><span class="macro">!</span>([<span class="ident">Interest</span>] <span class="op">=</span><span class="op">></span> <span class="ident">interest_derive</span>);
|
||||
|
||||
<span class="comment">/*
|
||||
* Test Case
|
||||
*/</span>
|
||||
<span class="kw">fn</span> <span class="ident">main</span>() {
|
||||
<span class="ident">synstructure</span>::<span class="macro">test_derive</span><span class="macro">!</span>{
|
||||
<span class="ident">interest_derive</span> {
|
||||
<span class="kw">enum</span> <span class="ident">A</span><span class="op"><</span><span class="ident">T</span><span class="op">></span> {
|
||||
<span class="ident">B</span>(<span class="ident">i32</span>, <span class="ident">T</span>),
|
||||
<span class="ident">C</span>(<span class="ident">i32</span>),
|
||||
}
|
||||
}
|
||||
<span class="ident">expands</span> <span class="ident">to</span> {
|
||||
<span class="attribute">#[<span class="ident">allow</span>(<span class="ident">non_upper_case_globals</span>)]</span>
|
||||
<span class="kw">const</span> <span class="ident">_DERIVE_synstructure_test_traits_Interest_FOR_A</span>: () <span class="op">=</span> {
|
||||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">synstructure_test_traits</span>;
|
||||
<span class="kw">impl</span><span class="op"><</span><span class="ident">T</span><span class="op">></span> <span class="ident">synstructure_test_traits</span>::<span class="ident">Interest</span> <span class="kw">for</span> <span class="ident">A</span><span class="op"><</span><span class="ident">T</span><span class="op">></span>
|
||||
<span class="kw">where</span> <span class="ident">T</span>: <span class="ident">synstructure_test_traits</span>::<span class="ident">Interest</span>
|
||||
{
|
||||
<span class="kw">fn</span> <span class="ident">interesting</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">bool</span> {
|
||||
<span class="kw">match</span> <span class="kw-2">*</span><span class="self">self</span> {
|
||||
<span class="ident">A</span>::<span class="ident">B</span>(<span class="kw-2">ref</span> <span class="ident">__binding_0</span>, <span class="kw-2">ref</span> <span class="ident">__binding_1</span>,) <span class="op">=</span><span class="op">></span> {
|
||||
<span class="bool-val">false</span> <span class="op">|</span><span class="op">|</span>
|
||||
<span class="ident">synstructure_test_traits</span>::<span class="ident">Interest</span>::<span class="ident">interesting</span>(<span class="ident">__binding_0</span>) <span class="op">|</span><span class="op">|</span>
|
||||
<span class="ident">synstructure_test_traits</span>::<span class="ident">Interest</span>::<span class="ident">interesting</span>(<span class="ident">__binding_1</span>)
|
||||
}
|
||||
<span class="ident">A</span>::<span class="ident">C</span>(<span class="kw-2">ref</span> <span class="ident">__binding_0</span>,) <span class="op">=</span><span class="op">></span> {
|
||||
<span class="bool-val">false</span> <span class="op">|</span><span class="op">|</span>
|
||||
<span class="ident">synstructure_test_traits</span>::<span class="ident">Interest</span>::<span class="ident">interesting</span>(<span class="ident">__binding_0</span>)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}</pre></div>
|
||||
<p>For more example usage, consider investigating the <code>abomonation_derive</code> crate,
|
||||
which makes use of this crate, and is fairly simple.</p>
|
||||
</div><h2 id="macros" class="section-header"><a href="#macros">Macros</a></h2>
|
||||
<table><tr class="module-item"><td><a class="macro" href="macro.decl_attribute.html" title="synstructure::decl_attribute macro">decl_attribute</a></td><td class="docblock-short"><p>The <code>decl_attribute!</code> macro declares a custom attribute wrapper. It will
|
||||
parse the incoming <code>TokenStream</code> into a <code>synstructure::Structure</code> object,
|
||||
and pass it into the inner function.</p>
|
||||
</td></tr><tr class="module-item"><td><a class="macro" href="macro.decl_derive.html" title="synstructure::decl_derive macro">decl_derive</a></td><td class="docblock-short"><p>The <code>decl_derive!</code> macro declares a custom derive wrapper. It will parse the
|
||||
incoming <code>TokenStream</code> into a <code>synstructure::Structure</code> object, and pass it
|
||||
into the inner function.</p>
|
||||
</td></tr><tr class="module-item"><td><a class="macro" href="macro.test_derive.html" title="synstructure::test_derive macro">test_derive</a></td><td class="docblock-short"><p>Run a test on a custom derive. This macro expands both the original struct
|
||||
and the expansion to ensure that they compile correctly, and confirms that
|
||||
feeding the original struct into the named derive will produce the written
|
||||
output.</p>
|
||||
</td></tr></table><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
|
||||
<table><tr class="module-item"><td><a class="struct" href="struct.BindingInfo.html" title="synstructure::BindingInfo struct">BindingInfo</a></td><td class="docblock-short"><p>Information about a specific binding. This contains both an <code>Ident</code>
|
||||
reference to the given field, and the syn <code>&'a Field</code> descriptor for that
|
||||
field.</p>
|
||||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.Structure.html" title="synstructure::Structure struct">Structure</a></td><td class="docblock-short"><p>A wrapper around a <code>syn::DeriveInput</code> which provides utilities for creating
|
||||
custom derive trait implementations.</p>
|
||||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.VariantAst.html" title="synstructure::VariantAst struct">VariantAst</a></td><td class="docblock-short"><p>This type is similar to <code>syn</code>'s <code>Variant</code> type, however each of the fields
|
||||
are references rather than owned. When this is used as the AST for a real
|
||||
variant, this struct simply borrows the fields of the <code>syn::Variant</code>,
|
||||
however this type may also be used as the sole variant for a struct.</p>
|
||||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.VariantInfo.html" title="synstructure::VariantInfo struct">VariantInfo</a></td><td class="docblock-short"><p>A wrapper around a <code>syn::DeriveInput</code>'s variant which provides utilities
|
||||
for destructuring <code>Variant</code>s with <code>match</code> expressions.</p>
|
||||
</td></tr></table><h2 id="enums" class="section-header"><a href="#enums">Enums</a></h2>
|
||||
<table><tr class="module-item"><td><a class="enum" href="enum.AddBounds.html" title="synstructure::AddBounds enum">AddBounds</a></td><td class="docblock-short"><p>Changes how bounds are added</p>
|
||||
</td></tr><tr class="module-item"><td><a class="enum" href="enum.BindStyle.html" title="synstructure::BindStyle enum">BindStyle</a></td><td class="docblock-short"><p>The type of binding to use when generating a pattern.</p>
|
||||
</td></tr></table><h2 id="traits" class="section-header"><a href="#traits">Traits</a></h2>
|
||||
<table><tr class="module-item"><td><a class="trait" href="trait.MacroResult.html" title="synstructure::MacroResult trait">MacroResult</a></td><td class="docblock-short"><p>Helper trait describing values which may be returned by macro implementation
|
||||
methods used by this crate's macros.</p>
|
||||
</td></tr></table><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2>
|
||||
<table><tr class="module-item"><td><a class="fn" href="fn.unpretty_print.html" title="synstructure::unpretty_print fn">unpretty_print</a></td><td class="docblock-short"><p>Dumps an unpretty version of a tokenstream. Takes any type which implements
|
||||
<code>Display</code>.</p>
|
||||
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "synstructure";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|
||||
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=macro.decl_attribute.html">
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="macro.decl_attribute.html">macro.decl_attribute.html</a>...</p>
|
||||
<script>location.replace("macro.decl_attribute.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,32 @@
|
||||
<!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="API documentation for the Rust `decl_attribute` macro in crate `synstructure`."><meta name="keywords" content="rust, rustlang, rust-lang, decl_attribute"><title>synstructure::decl_attribute - 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><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 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../synstructure/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">synstructure</a></p><script>window.sidebarCurrent = {name: "decl_attribute", ty: "macro", relpath: ""};</script><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" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><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" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><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/synstructure/macros.rs.html#147-164" title="goto source code">[src]</a></span><span class="in-band">Macro <a href="index.html">synstructure</a>::<wbr><a class="macro" href="">decl_attribute</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><div class="example-wrap"><pre class="rust macro">
|
||||
<span class="macro">macro_rules</span><span class="macro">!</span> <span class="ident">decl_attribute</span> {
|
||||
([<span class="macro-nonterminal">$</span><span class="macro-nonterminal">attribute</span>:<span class="ident">ident</span>] <span class="op">=</span><span class="op">></span> $(<span class="attribute">#[$(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">attrs</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>]</span>)<span class="op">*</span> <span class="macro-nonterminal">$</span><span class="macro-nonterminal">inner</span>:<span class="ident">path</span>) <span class="op">=</span><span class="op">></span> { ... };
|
||||
}</pre></div>
|
||||
</div><div class="docblock"><p>The <code>decl_attribute!</code> macro declares a custom attribute wrapper. It will
|
||||
parse the incoming <code>TokenStream</code> into a <code>synstructure::Structure</code> object,
|
||||
and pass it into the inner function.</p>
|
||||
<p>Your inner function should have the following type:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">fn</span> <span class="ident">attribute</span>(
|
||||
<span class="ident">attr</span>: <span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span>,
|
||||
<span class="ident">structure</span>: <span class="ident">synstructure</span>::<span class="ident">Structure</span>,
|
||||
) <span class="op">-</span><span class="op">></span> <span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span> {
|
||||
<span class="macro">unimplemented</span><span class="macro">!</span>()
|
||||
}</pre></div>
|
||||
<h1 id="usage" class="section-header"><a href="#usage">Usage</a></h1>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">fn</span> <span class="ident">attribute_interesting</span>(
|
||||
<span class="ident">_attr</span>: <span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span>,
|
||||
<span class="ident">_structure</span>: <span class="ident">synstructure</span>::<span class="ident">Structure</span>,
|
||||
) <span class="op">-</span><span class="op">></span> <span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span> {
|
||||
<span class="ident">quote</span>::<span class="macro">quote</span><span class="macro">!</span> { ... }
|
||||
}
|
||||
|
||||
<span class="macro">decl_attribute</span><span class="macro">!</span>([<span class="ident">interesting</span>] <span class="op">=</span><span class="op">></span> <span class="ident">attribute_interesting</span>);</pre></div>
|
||||
<p><em>This macro is available if <code>synstructure</code> is built with the <code>"proc-macro"</code>
|
||||
feature.</em></p>
|
||||
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "synstructure";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|
||||
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=macro.decl_derive.html">
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="macro.decl_derive.html">macro.decl_derive.html</a>...</p>
|
||||
<script>location.replace("macro.decl_derive.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,52 @@
|
||||
<!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="API documentation for the Rust `decl_derive` macro in crate `synstructure`."><meta name="keywords" content="rust, rustlang, rust-lang, decl_derive"><title>synstructure::decl_derive - 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><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 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../synstructure/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">synstructure</a></p><script>window.sidebarCurrent = {name: "decl_derive", ty: "macro", relpath: ""};</script><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" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><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" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><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/synstructure/macros.rs.html#88-108" title="goto source code">[src]</a></span><span class="in-band">Macro <a href="index.html">synstructure</a>::<wbr><a class="macro" href="">decl_derive</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><div class="example-wrap"><pre class="rust macro">
|
||||
<span class="macro">macro_rules</span><span class="macro">!</span> <span class="ident">decl_derive</span> {
|
||||
([<span class="macro-nonterminal">$</span><span class="macro-nonterminal">derives</span>:<span class="ident">ident</span> $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">derive_t</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>] <span class="op">=</span><span class="op">></span> $(<span class="attribute">#[$(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">attrs</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>]</span>)<span class="op">*</span> <span class="macro-nonterminal">$</span><span class="macro-nonterminal">inner</span>:<span class="ident">path</span>) <span class="op">=</span><span class="op">></span> { ... };
|
||||
}</pre></div>
|
||||
</div><div class="docblock"><p>The <code>decl_derive!</code> macro declares a custom derive wrapper. It will parse the
|
||||
incoming <code>TokenStream</code> into a <code>synstructure::Structure</code> object, and pass it
|
||||
into the inner function.</p>
|
||||
<p>Your inner function should take a <code>synstructure::Structure</code> by value, and
|
||||
return a type implementing <code>synstructure::MacroResult</code>, for example:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">fn</span> <span class="ident">derive_simple</span>(<span class="ident">input</span>: <span class="ident">synstructure</span>::<span class="ident">Structure</span>) <span class="op">-</span><span class="op">></span> <span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span> {
|
||||
<span class="macro">unimplemented</span><span class="macro">!</span>()
|
||||
}
|
||||
|
||||
<span class="kw">fn</span> <span class="ident">derive_result</span>(<span class="ident">input</span>: <span class="ident">synstructure</span>::<span class="ident">Structure</span>)
|
||||
<span class="op">-</span><span class="op">></span> <span class="ident">syn</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span><span class="op">></span>
|
||||
{
|
||||
<span class="macro">unimplemented</span><span class="macro">!</span>()
|
||||
}</pre></div>
|
||||
<h1 id="usage" class="section-header"><a href="#usage">Usage</a></h1><h3 id="without-attributes" class="section-header"><a href="#without-attributes">Without Attributes</a></h3>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">fn</span> <span class="ident">derive_interesting</span>(<span class="ident">_input</span>: <span class="ident">synstructure</span>::<span class="ident">Structure</span>) <span class="op">-</span><span class="op">></span> <span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span> {
|
||||
<span class="ident">quote</span>::<span class="macro">quote</span><span class="macro">!</span> { ... }
|
||||
}
|
||||
|
||||
<span class="macro">decl_derive</span><span class="macro">!</span>([<span class="ident">Interesting</span>] <span class="op">=</span><span class="op">></span> <span class="ident">derive_interesting</span>);</pre></div>
|
||||
<h3 id="with-attributes" class="section-header"><a href="#with-attributes">With Attributes</a></h3>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">fn</span> <span class="ident">derive_interesting</span>(<span class="ident">_input</span>: <span class="ident">synstructure</span>::<span class="ident">Structure</span>) <span class="op">-</span><span class="op">></span> <span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span> {
|
||||
<span class="ident">quote</span>::<span class="macro">quote</span><span class="macro">!</span> { ... }
|
||||
}
|
||||
|
||||
<span class="macro">decl_derive</span><span class="macro">!</span>([<span class="ident">Interesting</span>, <span class="ident">attributes</span>(<span class="ident">interesting_ignore</span>)] <span class="op">=</span><span class="op">></span> <span class="ident">derive_interesting</span>);</pre></div>
|
||||
<h3 id="decl-attributes--doc-comments" class="section-header"><a href="#decl-attributes--doc-comments">Decl Attributes & Doc Comments</a></h3>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">fn</span> <span class="ident">derive_interesting</span>(<span class="ident">_input</span>: <span class="ident">synstructure</span>::<span class="ident">Structure</span>) <span class="op">-</span><span class="op">></span> <span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span> {
|
||||
<span class="ident">quote</span>::<span class="macro">quote</span><span class="macro">!</span> { ... }
|
||||
}
|
||||
|
||||
<span class="macro">decl_derive</span><span class="macro">!</span> {
|
||||
[<span class="ident">Interesting</span>] <span class="op">=</span><span class="op">></span>
|
||||
<span class="attribute">#[<span class="ident">allow</span>(<span class="ident">some_lint</span>)]</span>
|
||||
<span class="doccomment">/// Documentation Comments</span>
|
||||
<span class="ident">derive_interesting</span>
|
||||
}</pre></div>
|
||||
<p><em>This macro is available if <code>synstructure</code> is built with the <code>"proc-macro"</code>
|
||||
feature.</em></p>
|
||||
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "synstructure";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|
||||
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=macro.test_derive.html">
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="macro.test_derive.html">macro.test_derive.html</a>...</p>
|
||||
<script>location.replace("macro.test_derive.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,35 @@
|
||||
<!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="API documentation for the Rust `test_derive` macro in crate `synstructure`."><meta name="keywords" content="rust, rustlang, rust-lang, test_derive"><title>synstructure::test_derive - 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><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 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../synstructure/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">synstructure</a></p><script>window.sidebarCurrent = {name: "test_derive", ty: "macro", relpath: ""};</script><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" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><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" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><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/synstructure/macros.rs.html#197-250" title="goto source code">[src]</a></span><span class="in-band">Macro <a href="index.html">synstructure</a>::<wbr><a class="macro" href="">test_derive</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><div class="example-wrap"><pre class="rust macro">
|
||||
<span class="macro">macro_rules</span><span class="macro">!</span> <span class="ident">test_derive</span> {
|
||||
(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">name</span>:<span class="ident">path</span> { $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">i</span>:<span class="ident">tt</span>)<span class="op">*</span> } <span class="ident">expands</span> <span class="ident">to</span> { $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">o</span>:<span class="ident">tt</span>)<span class="op">*</span> }) <span class="op">=</span><span class="op">></span> { ... };
|
||||
(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">name</span>:<span class="ident">path</span> { $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">i</span>:<span class="ident">tt</span>)<span class="op">*</span> } <span class="ident">expands</span> <span class="ident">to</span> { $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">o</span>:<span class="ident">tt</span>)<span class="op">*</span> } <span class="ident">no_build</span>) <span class="op">=</span><span class="op">></span> { ... };
|
||||
}</pre></div>
|
||||
</div><div class="docblock"><p>Run a test on a custom derive. This macro expands both the original struct
|
||||
and the expansion to ensure that they compile correctly, and confirms that
|
||||
feeding the original struct into the named derive will produce the written
|
||||
output.</p>
|
||||
<p>You can add <code>no_build</code> to the end of the macro invocation to disable
|
||||
checking that the written code compiles. This is useful in contexts where
|
||||
the procedural macro cannot depend on the crate where it is used during
|
||||
tests.</p>
|
||||
<h1 id="usage" class="section-header"><a href="#usage">Usage</a></h1>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||||
<span class="kw">fn</span> <span class="ident">test_derive_example</span>(<span class="ident">_s</span>: <span class="ident">synstructure</span>::<span class="ident">Structure</span>)
|
||||
<span class="op">-</span><span class="op">></span> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">proc_macro2</span>::<span class="ident">TokenStream</span>, <span class="ident">syn</span>::<span class="ident">Error</span><span class="op">></span>
|
||||
{
|
||||
<span class="prelude-val">Ok</span>(<span class="ident">quote</span>::<span class="macro">quote</span><span class="macro">!</span> { <span class="kw">const</span> <span class="ident">YOUR_OUTPUT</span>: <span class="kw-2">&</span><span class="lifetime">'static</span> <span class="ident">str</span> <span class="op">=</span> <span class="string">"here"</span>; })
|
||||
}
|
||||
|
||||
<span class="kw">fn</span> <span class="ident">main</span>() {
|
||||
<span class="ident">synstructure</span>::<span class="macro">test_derive</span><span class="macro">!</span>{
|
||||
<span class="ident">test_derive_example</span> {
|
||||
<span class="kw">struct</span> <span class="ident">A</span>;
|
||||
}
|
||||
<span class="ident">expands</span> <span class="ident">to</span> {
|
||||
<span class="kw">const</span> <span class="ident">YOUR_OUTPUT</span>: <span class="kw-2">&</span><span class="lifetime">'static</span> <span class="ident">str</span> <span class="op">=</span> <span class="string">"here"</span>;
|
||||
}
|
||||
}
|
||||
}</pre></div>
|
||||
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "synstructure";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
initSidebarItems({"enum":[["AddBounds","Changes how bounds are added"],["BindStyle","The type of binding to use when generating a pattern."]],"fn":[["unpretty_print","Dumps an unpretty version of a tokenstream. Takes any type which implements `Display`."]],"macro":[["decl_attribute","The `decl_attribute!` macro declares a custom attribute wrapper. It will parse the incoming `TokenStream` into a `synstructure::Structure` object, and pass it into the inner function."],["decl_derive","The `decl_derive!` macro declares a custom derive wrapper. It will parse the incoming `TokenStream` into a `synstructure::Structure` object, and pass it into the inner function."],["test_derive","Run a test on a custom derive. This macro expands both the original struct and the expansion to ensure that they compile correctly, and confirms that feeding the original struct into the named derive will produce the written output."]],"struct":[["BindingInfo","Information about a specific binding. This contains both an `Ident` reference to the given field, and the syn `&'a Field` descriptor for that field."],["Structure","A wrapper around a `syn::DeriveInput` which provides utilities for creating custom derive trait implementations."],["VariantAst","This type is similar to `syn`'s `Variant` type, however each of the fields are references rather than owned. When this is used as the AST for a real variant, this struct simply borrows the fields of the `syn::Variant`, however this type may also be used as the sole variant for a struct."],["VariantInfo","A wrapper around a `syn::DeriveInput`'s variant which provides utilities for destructuring `Variant`s with `match` expressions."]],"trait":[["MacroResult","Helper trait describing values which may be returned by macro implementation methods used by this crate's macros."]]});
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user