Files
google-apis-rs/darling/index.html
2024-03-05 21:06:01 +01:00

58 lines
14 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="Darling"><title>darling - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="darling" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[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">&#9776;</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../darling/index.html">darling</a><span class="version">0.20.3</span></h2></div><div class="sidebar-elems"><ul class="block">
<li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li><li><a href="#types">Type Aliases</a></li></ul></section></div></nav><div class="sidebar-resizer"></div>
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../darling/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">darling</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../src/darling/lib.rs.html#1-110">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="darling"><a href="#darling">Darling</a></h2>
<p>Darling is a tool for declarative attribute parsing in proc macro implementations.</p>
<h3 id="design"><a href="#design">Design</a></h3>
<p>Darling takes considerable design inspiration from <a href="https://serde.rs"><code>serde</code></a>. A data structure that can be
read from any attribute implements <code>FromMeta</code> (or has an implementation automatically
generated using <code>derive</code>). Any crate can provide <code>FromMeta</code> implementations, even one not
specifically geared towards proc-macro authors.</p>
<p>Proc-macro crates should provide their own structs which implement or derive <code>FromDeriveInput</code>,
<code>FromField</code>, <code>FromVariant</code>, <code>FromGenerics</code>, <em>et alia</em> to gather settings relevant to their operation.</p>
<h3 id="attributes"><a href="#attributes">Attributes</a></h3>
<p>There are a number of attributes that <code>darling</code> exposes to enable finer-grained control over the code
it generates.</p>
<ul>
<li><strong>Field renaming</strong>: You can use <code>#[darling(rename=&quot;new_name&quot;)]</code> on a field to change the name Darling looks for.
You can also use <code>#[darling(rename_all=&quot;...&quot;)]</code> at the struct or enum level to apply a casing rule to all fields or variants.</li>
<li><strong>Map function</strong>: You can use <code>#[darling(map=&quot;path::to::function&quot;)]</code> to run code on a field before its stored in the struct.</li>
<li><strong>Default values</strong>: You can use <code>#[darling(default)]</code> at the type or field level to use that types default value to fill
in values not specified by the caller.</li>
<li><strong>Skipped fields</strong>: You can skip a variant or field using <code>#[darling(skip)]</code>. Fields marked with this will fall back to
<code>Default::default()</code> for their value, but you can override that with an explicit default or a value from the type-level default.</li>
</ul>
<h3 id="forwarded-fields"><a href="#forwarded-fields">Forwarded Fields</a></h3>
<p>All derivable traits except <code>FromMeta</code> support forwarding some fields from the input AST to the derived struct.
These fields are matched up by identifier <strong>before</strong> <code>rename</code> attribute values are considered,
allowing you to use their names for your own properties.
The deriving struct is responsible for making sure the types of fields it chooses to declare are compatible with this table.</p>
<p>A deriving struct is free to include or exclude any of the fields below.</p>
<h4 id="fromderiveinput"><a href="#fromderiveinput"><code>FromDeriveInput</code></a></h4><div><table><thead><tr><th>Field name</th><th>Type</th><th>Meaning</th></tr></thead><tbody>
<tr><td><code>ident</code></td><td><code>syn::Ident</code></td><td>The identifier of the passed-in type</td></tr>
<tr><td><code>vis</code></td><td><code>syn::Visibility</code></td><td>The visibility of the passed-in type</td></tr>
<tr><td><code>generics</code></td><td><code>T: darling::FromGenerics</code></td><td>The generics of the passed-in type. This can be <code>syn::Generics</code>, <code>darling::ast::Generics</code>, or any compatible type.</td></tr>
<tr><td><code>data</code></td><td><code>darling::ast::Data</code></td><td>The body of the passed-in type</td></tr>
<tr><td><code>attrs</code></td><td><code>Vec&lt;syn::Attribute&gt;</code></td><td>The forwarded attributes from the passed in type. These are controlled using the <code>forward_attrs</code> attribute.</td></tr>
</tbody></table>
</div><h4 id="fromfield"><a href="#fromfield"><code>FromField</code></a></h4><div><table><thead><tr><th>Field name</th><th>Type</th><th>Meaning</th></tr></thead><tbody>
<tr><td><code>ident</code></td><td><code>Option&lt;syn::Ident&gt;</code></td><td>The identifier of the passed-in field, or <code>None</code> for tuple fields</td></tr>
<tr><td><code>vis</code></td><td><code>syn::Visibility</code></td><td>The visibility of the passed-in field</td></tr>
<tr><td><code>ty</code></td><td><code>syn::Type</code></td><td>The type of the passed-in field</td></tr>
<tr><td><code>attrs</code></td><td><code>Vec&lt;syn::Attribute&gt;</code></td><td>The forwarded attributes from the passed in field. These are controlled using the <code>forward_attrs</code> attribute.</td></tr>
</tbody></table>
</div><h4 id="fromtypeparam"><a href="#fromtypeparam"><code>FromTypeParam</code></a></h4><div><table><thead><tr><th>Field name</th><th>Type</th><th>Meaning</th></tr></thead><tbody>
<tr><td><code>ident</code></td><td><code>syn::Ident</code></td><td>The identifier of the passed-in type param</td></tr>
<tr><td><code>bounds</code></td><td><code>Vec&lt;syn::TypeParamBound&gt;</code></td><td>The bounds applied to the type param</td></tr>
<tr><td><code>default</code></td><td><code>Option&lt;syn::Type&gt;</code></td><td>The default type of the parameter, if one exists</td></tr>
<tr><td><code>attrs</code></td><td><code>Vec&lt;syn::Attribute&gt;</code></td><td>The forwarded attributes from the passed in type param. These are controlled using the <code>forward_attrs</code> attribute.</td></tr>
</tbody></table>
</div><h4 id="fromvariant"><a href="#fromvariant"><code>FromVariant</code></a></h4><div><table><thead><tr><th>Field name</th><th>Type</th><th>Meaning</th></tr></thead><tbody>
<tr><td><code>ident</code></td><td><code>syn::Ident</code></td><td>The identifier of the passed-in variant</td></tr>
<tr><td><code>discriminant</code></td><td><code>Option&lt;syn::Expr&gt;</code></td><td>For a variant such as <code>Example = 2</code>, the <code>2</code></td></tr>
<tr><td><code>fields</code></td><td><code>darling::ast::Fields&lt;T&gt; where T: FromField</code></td><td>The fields associated with the variant</td></tr>
<tr><td><code>attrs</code></td><td><code>Vec&lt;syn::Attribute&gt;</code></td><td>The forwarded attributes from the passed in variant. These are controlled using the <code>forward_attrs</code> attribute.</td></tr>
</tbody></table>
</div></div></details><h2 id="modules" class="section-header"><a href="#modules">Modules</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="ast/index.html" title="mod darling::ast">ast</a></div><div class="desc docblock-short">Utility types for working with the AST.</div></li><li><div class="item-name"><a class="mod" href="error/index.html" title="mod darling::error">error</a></div><div class="desc docblock-short">The <code>darling::Error</code> type, the multiple error <code>Accumulator</code>, and their internals.</div></li><li><div class="item-name"><a class="mod" href="usage/index.html" title="mod darling::usage">usage</a></div><div class="desc docblock-short">Traits and types used for tracking the usage of generic parameters through a proc-macro input.</div></li><li><div class="item-name"><a class="mod" href="util/index.html" title="mod darling::util">util</a></div><div class="desc docblock-short">Utility types for attribute parsing.</div></li></ul><h2 id="macros" class="section-header"><a href="#macros">Macros</a></h2><ul class="item-table"><li><div class="item-name"><a class="macro" href="macro.uses_lifetimes.html" title="macro darling::uses_lifetimes">uses_lifetimes</a></div><div class="desc docblock-short">Generator for <code>UsesLifetimes</code> impls that unions the used lifetimes of the selected fields.</div></li><li><div class="item-name"><a class="macro" href="macro.uses_type_params.html" title="macro darling::uses_type_params">uses_type_params</a></div><div class="desc docblock-short">Generator for <code>UsesTypeParam</code> impls that unions the used type parameters of the selected fields.</div></li></ul><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Error.html" title="struct darling::Error">Error</a></div><div class="desc docblock-short">An error encountered during attribute parsing.</div></li></ul><h2 id="traits" class="section-header"><a href="#traits">Traits</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.FromAttributes.html" title="trait darling::FromAttributes">FromAttributes</a></div><div class="desc docblock-short">Create an instance by parsing a list of attributes.</div></li><li><div class="item-name"><a class="trait" href="trait.FromDeriveInput.html" title="trait darling::FromDeriveInput">FromDeriveInput</a></div><div class="desc docblock-short">Creates an instance by parsing an entire proc-macro <code>derive</code> input,
including the, identity, generics, and visibility of the type.</div></li><li><div class="item-name"><a class="trait" href="trait.FromField.html" title="trait darling::FromField">FromField</a></div><div class="desc docblock-short">Creates an instance by parsing an individual field and its attributes.</div></li><li><div class="item-name"><a class="trait" href="trait.FromGenericParam.html" title="trait darling::FromGenericParam">FromGenericParam</a></div><div class="desc docblock-short">Creates an instance by parsing a specific <code>syn::GenericParam</code>.
This can be a type param, a lifetime, or a const param.</div></li><li><div class="item-name"><a class="trait" href="trait.FromGenerics.html" title="trait darling::FromGenerics">FromGenerics</a></div><div class="desc docblock-short">Creates an instance by parsing an entire generics declaration, including the
<code>where</code> clause.</div></li><li><div class="item-name"><a class="trait" href="trait.FromMeta.html" title="trait darling::FromMeta">FromMeta</a></div><div class="desc docblock-short">Create an instance from an item in an attribute declaration.</div></li><li><div class="item-name"><a class="trait" href="trait.FromTypeParam.html" title="trait darling::FromTypeParam">FromTypeParam</a></div><div class="desc docblock-short">Creates an instance by parsing an individual type_param and its attributes.</div></li><li><div class="item-name"><a class="trait" href="trait.FromVariant.html" title="trait darling::FromVariant">FromVariant</a></div><div class="desc docblock-short">Creates an instance from a specified <code>syn::Variant</code>.</div></li></ul><h2 id="types" class="section-header"><a href="#types">Type Aliases</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.Result.html" title="type darling::Result">Result</a></div><div class="desc docblock-short">An alias of <code>Result</code> specific to attribute parsing.</div></li></ul></section></div></main></body></html>