Initial docs commit

This commit is contained in:
Uttarayan Mondal
2021-03-15 01:27:34 +05:30
commit d5ecda4c73
20211 changed files with 1370362 additions and 0 deletions
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,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../serde/de/struct.IgnoredAny.html">
</head>
<body>
<p>Redirecting to <a href="../../../serde/de/struct.IgnoredAny.html">../../../serde/de/struct.IgnoredAny.html</a>...</p>
<script>location.replace("../../../serde/de/struct.IgnoredAny.html" + location.search + location.hash);</script>
</body>
</html>
+157
View File
@@ -0,0 +1,157 @@
<!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="Generic data structure deserialization framework."><meta name="keywords" content="rust, rustlang, rust-lang, de"><title>serde::de - 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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Module de</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#reexports">Re-exports</a></li><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li></ul></div><p class="location"><a href="../index.html">serde</a></p><div id="sidebar-vars" data-name="de" data-ty="mod" 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" 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="in-band">Module <a href="../index.html">serde</a>::<wbr><a class="mod" href="">de</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/de/mod.rs.html#1-2275" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Generic data structure deserialization framework.</p>
<p>The two most important traits in this module are <a href="../trait.Deserialize.html"><code>Deserialize</code></a> and
<a href="../trait.Deserializer.html"><code>Deserializer</code></a>.</p>
<ul>
<li><strong>A type that implements <code>Deserialize</code> is a data structure</strong> that can be
deserialized from any data format supported by Serde, and conversely</li>
<li><strong>A type that implements <code>Deserializer</code> is a data format</strong> that can
deserialize any data structure supported by Serde.</li>
</ul>
<h1 id="the-deserialize-trait" class="section-header"><a href="#the-deserialize-trait">The Deserialize trait</a></h1>
<p>Serde provides <a href="../trait.Deserialize.html"><code>Deserialize</code></a> implementations for many Rust primitive and
standard library types. The complete list is below. All of these can be
deserialized using Serde out of the box.</p>
<p>Additionally, Serde provides a procedural macro called <a href="https://crates.io/crates/serde_derive"><code>serde_derive</code></a> to
automatically generate <a href="../trait.Deserialize.html"><code>Deserialize</code></a> implementations for structs and enums
in your program. See the <a href="https://serde.rs/derive.html">derive section of the manual</a> for how to use this.</p>
<p>In rare cases it may be necessary to implement <a href="../trait.Deserialize.html"><code>Deserialize</code></a> manually for
some type in your program. See the <a href="https://serde.rs/impl-deserialize.html">Implementing <code>Deserialize</code></a> section of
the manual for more about this.</p>
<p>Third-party crates may provide <a href="../trait.Deserialize.html"><code>Deserialize</code></a> implementations for types
that they expose. For example the <a href="https://crates.io/crates/linked-hash-map"><code>linked-hash-map</code></a> crate provides a
<a href="https://docs.rs/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap.html"><code>LinkedHashMap&lt;K, V&gt;</code></a> type that is deserializable by Serde because the
crate provides an implementation of <a href="../trait.Deserialize.html"><code>Deserialize</code></a> for it.</p>
<h1 id="the-deserializer-trait" class="section-header"><a href="#the-deserializer-trait">The Deserializer trait</a></h1>
<p><a href="../trait.Deserializer.html"><code>Deserializer</code></a> implementations are provided by third-party crates, for
example <a href="https://github.com/serde-rs/json"><code>serde_json</code></a>, <a href="https://github.com/dtolnay/serde-yaml"><code>serde_yaml</code></a> and <a href="https://github.com/servo/bincode"><code>bincode</code></a>.</p>
<p>A partial list of well-maintained formats is given on the <a href="https://serde.rs/#data-formats">Serde
website</a>.</p>
<h1 id="implementations-of-deserialize-provided-by-serde" class="section-header"><a href="#implementations-of-deserialize-provided-by-serde">Implementations of Deserialize provided by Serde</a></h1>
<p>This is a slightly different set of types than what is supported for
serialization. Some types can be serialized by Serde but not deserialized.
One example is <code>OsStr</code>.</p>
<ul>
<li><strong>Primitive types</strong>:
<ul>
<li>bool</li>
<li>i8, i16, i32, i64, i128, isize</li>
<li>u8, u16, u32, u64, u128, usize</li>
<li>f32, f64</li>
<li>char</li>
</ul>
</li>
<li><strong>Compound types</strong>:
<ul>
<li>[T; 0] through [T; 32]</li>
<li>tuples up to size 16</li>
</ul>
</li>
<li><strong>Common standard library types</strong>:
<ul>
<li>String</li>
<li>Option&lt;T&gt;</li>
<li>Result&lt;T, E&gt;</li>
<li>PhantomData&lt;T&gt;</li>
</ul>
</li>
<li><strong>Wrapper types</strong>:
<ul>
<li>Box&lt;T&gt;</li>
<li>Box&lt;[T]&gt;</li>
<li>Box&lt;str&gt;</li>
<li>Cow&lt;a, T&gt;</li>
<li>Cell&lt;T&gt;</li>
<li>RefCell&lt;T&gt;</li>
<li>Mutex&lt;T&gt;</li>
<li>RwLock&lt;T&gt;</li>
<li>Rc&lt;T&gt;<em>(if</em> features = [“rc”] <em>is enabled)</em></li>
<li>Arc&lt;T&gt;<em>(if</em> features = [“rc”] <em>is enabled)</em></li>
</ul>
</li>
<li><strong>Collection types</strong>:
<ul>
<li>BTreeMap&lt;K, V&gt;</li>
<li>BTreeSet&lt;T&gt;</li>
<li>BinaryHeap&lt;T&gt;</li>
<li>HashMap&lt;K, V, H&gt;</li>
<li>HashSet&lt;T, H&gt;</li>
<li>LinkedList&lt;T&gt;</li>
<li>VecDeque&lt;T&gt;</li>
<li>Vec&lt;T&gt;</li>
</ul>
</li>
<li><strong>Zero-copy types</strong>:
<ul>
<li>&amp;str</li>
<li>&amp;[u8]</li>
</ul>
</li>
<li><strong>FFI types</strong>:
<ul>
<li>CString</li>
<li>Box&lt;CStr&gt;</li>
<li>OsString</li>
</ul>
</li>
<li><strong>Miscellaneous standard library types</strong>:
<ul>
<li>Duration</li>
<li>SystemTime</li>
<li>Path</li>
<li>PathBuf</li>
<li>Range&lt;T&gt;</li>
<li>RangeInclusive&lt;T&gt;</li>
<li>Bound&lt;T&gt;</li>
<li>num::NonZero*</li>
<li><code>!</code> <em>(unstable)</em></li>
</ul>
</li>
<li><strong>Net types</strong>:
<ul>
<li>IpAddr</li>
<li>Ipv4Addr</li>
<li>Ipv6Addr</li>
<li>SocketAddr</li>
<li>SocketAddrV4</li>
<li>SocketAddrV6</li>
</ul>
</li>
</ul>
</div><h2 id="reexports" class="section-header"><a href="#reexports">Re-exports</a></h2>
<table><tr><td><code>pub use std::error::<a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">Error</a> as StdError;</code></td></tr></table><h2 id="modules" class="section-header"><a href="#modules">Modules</a></h2>
<table><tr class="module-item"><td><a class="mod" href="value/index.html" title="serde::de::value mod">value</a></td><td class="docblock-short"><p>Building blocks for deserializing basic values using the <code>IntoDeserializer</code>
trait.</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.IgnoredAny.html" title="serde::de::IgnoredAny struct">IgnoredAny</a></td><td class="docblock-short"><p>An efficient way of discarding data from a deserializer.</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.Unexpected.html" title="serde::de::Unexpected enum">Unexpected</a></td><td class="docblock-short"><p><code>Unexpected</code> represents an unexpected invocation of any one of the <code>Visitor</code>
trait methods.</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.Deserialize.html" title="serde::de::Deserialize trait">Deserialize</a></td><td class="docblock-short"><p>A <strong>data structure</strong> that can be deserialized from any data format supported
by Serde.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.DeserializeOwned.html" title="serde::de::DeserializeOwned trait">DeserializeOwned</a></td><td class="docblock-short"><p>A data structure that can be deserialized without borrowing any data from
the deserializer.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.DeserializeSeed.html" title="serde::de::DeserializeSeed trait">DeserializeSeed</a></td><td class="docblock-short"><p><code>DeserializeSeed</code> is the stateful form of the <code>Deserialize</code> trait. If you
ever find yourself looking for a way to pass data into a <code>Deserialize</code> impl,
this trait is the way to do it.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.Deserializer.html" title="serde::de::Deserializer trait">Deserializer</a></td><td class="docblock-short"><p>A <strong>data format</strong> that can deserialize any data structure supported by
Serde.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.EnumAccess.html" title="serde::de::EnumAccess trait">EnumAccess</a></td><td class="docblock-short"><p>Provides a <code>Visitor</code> access to the data of an enum in the input.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.Error.html" title="serde::de::Error trait">Error</a></td><td class="docblock-short"><p>The <code>Error</code> trait allows <code>Deserialize</code> implementations to create descriptive
error messages belonging to the <code>Deserializer</code> against which they are
currently running.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.Expected.html" title="serde::de::Expected trait">Expected</a></td><td class="docblock-short"><p><code>Expected</code> represents an explanation of what data a <code>Visitor</code> was expecting
to receive.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.IntoDeserializer.html" title="serde::de::IntoDeserializer trait">IntoDeserializer</a></td><td class="docblock-short"><p>Converts an existing value into a <code>Deserializer</code> from which other values can
be deserialized.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.MapAccess.html" title="serde::de::MapAccess trait">MapAccess</a></td><td class="docblock-short"><p>Provides a <code>Visitor</code> access to each entry of a map in the input.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.SeqAccess.html" title="serde::de::SeqAccess trait">SeqAccess</a></td><td class="docblock-short"><p>Provides a <code>Visitor</code> access to each element of a sequence in the input.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.VariantAccess.html" title="serde::de::VariantAccess trait">VariantAccess</a></td><td class="docblock-short"><p><code>VariantAccess</code> is a visitor that is created by the <code>Deserializer</code> and
passed to the <code>Deserialize</code> to deserialize the content of a particular enum
variant.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.Visitor.html" title="serde::de::Visitor trait">Visitor</a></td><td class="docblock-short"><p>This trait represents a visitor that walks through a deserializer.</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
+1
View File
@@ -0,0 +1 @@
initSidebarItems({"enum":[["Unexpected","`Unexpected` represents an unexpected invocation of any one of the `Visitor` trait methods."]],"mod":[["value","Building blocks for deserializing basic values using the `IntoDeserializer` trait."]],"struct":[["IgnoredAny","An efficient way of discarding data from a deserializer."]],"trait":[["Deserialize","A data structure that can be deserialized from any data format supported by Serde."],["DeserializeOwned","A data structure that can be deserialized without borrowing any data from the deserializer."],["DeserializeSeed","`DeserializeSeed` is the stateful form of the `Deserialize` trait. If you ever find yourself looking for a way to pass data into a `Deserialize` impl, this trait is the way to do it."],["Deserializer","A data format that can deserialize any data structure supported by Serde."],["EnumAccess","Provides a `Visitor` access to the data of an enum in the input."],["Error","The `Error` trait allows `Deserialize` implementations to create descriptive error messages belonging to the `Deserializer` against which they are currently running."],["Expected","`Expected` represents an explanation of what data a `Visitor` was expecting to receive."],["IntoDeserializer","Converts an existing value into a `Deserializer` from which other values can be deserialized."],["MapAccess","Provides a `Visitor` access to each entry of a map in the input."],["SeqAccess","Provides a `Visitor` access to each element of a sequence in the input."],["VariantAccess","`VariantAccess` is a visitor that is created by the `Deserializer` and passed to the `Deserialize` to deserialize the content of a particular enum variant."],["Visitor","This trait represents a visitor that walks through a deserializer."]]});
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+25
View File
@@ -0,0 +1,25 @@
<!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 data structure that can be deserialized without borrowing any data from the deserializer."><meta name="keywords" content="rust, rustlang, rust-lang, DeserializeOwned"><title>serde::de::DeserializeOwned - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait DeserializeOwned</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">de</a></p><div id="sidebar-vars" data-name="DeserializeOwned" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">de</a>::<wbr><a class="trait" href="">DeserializeOwned</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/de/mod.rs.html#602" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait DeserializeOwned: for&lt;'de&gt; <a class="trait" href="../../serde/trait.Deserialize.html" title="trait serde::Deserialize">Deserialize</a>&lt;'de&gt; { }</pre></div><div class="docblock"><p>A data structure that can be deserialized without borrowing any data from
the deserializer.</p>
<p>This is primarily useful for trait bounds on functions. For example a
<code>from_str</code> function may be able to deserialize a data structure that borrows
from the input string, but a <code>from_reader</code> function may only deserialize
owned data.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">fn</span> <span class="ident">from_str</span><span class="op">&lt;</span><span class="lifetime">&#39;a</span>, <span class="ident">T</span><span class="op">&gt;</span>(<span class="ident">s</span>: <span class="kw-2">&amp;</span><span class="lifetime">&#39;a</span> <span class="ident">str</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">T</span>: <span class="ident">Deserialize</span><span class="op">&lt;</span><span class="lifetime">&#39;a</span><span class="op">&gt;</span>;
<span class="kw">fn</span> <span class="ident">from_reader</span><span class="op">&lt;</span><span class="ident">R</span>, <span class="ident">T</span><span class="op">&gt;</span>(<span class="ident">rdr</span>: <span class="ident">R</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">R</span>: <span class="ident">Read</span>,
<span class="ident">T</span>: <span class="ident">DeserializeOwned</span>;</pre></div>
<h1 id="lifetime" class="section-header"><a href="#lifetime">Lifetime</a></h1>
<p>The relationship between <code>Deserialize</code> and <code>DeserializeOwned</code> in trait
bounds is explained in more detail on the page <a href="https://serde.rs/lifetimes.html">Understanding deserializer
lifetimes</a>.</p>
</div><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-DeserializeOwned" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="../../serde/de/trait.DeserializeOwned.html" title="trait serde::de::DeserializeOwned">DeserializeOwned</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: for&lt;'de&gt; <a class="trait" href="../../serde/trait.Deserialize.html" title="trait serde::Deserialize">Deserialize</a>&lt;'de&gt;,&nbsp;</span></code><a href="#impl-DeserializeOwned" class="anchor"></a><a class="srclink" href="../../src/serde/de/mod.rs.html#603" title="goto source code">[src]</a></h3><div class="impl-items"></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/de/trait.DeserializeOwned.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
+135
View File
@@ -0,0 +1,135 @@
<!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="`DeserializeSeed` is the stateful form of the `Deserialize` trait. If you ever find yourself looking for a way to pass data into a `Deserialize` impl, this trait is the way to do it."><meta name="keywords" content="rust, rustlang, rust-lang, DeserializeSeed"><title>serde::de::DeserializeSeed - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait DeserializeSeed</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Value">Value</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.deserialize">deserialize</a></div><a class="sidebar-title" href="#foreign-impls">Implementations on Foreign Types</a><div class="sidebar-links"><a href="#impl-DeserializeSeed%3C%27de%3E-for-PhantomData%3CT%3E">PhantomData&lt;T&gt;</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">de</a></p><div id="sidebar-vars" data-name="DeserializeSeed" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">de</a>::<wbr><a class="trait" href="">DeserializeSeed</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/de/mod.rs.html#763-772" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait DeserializeSeed&lt;'de&gt;: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
type <a href="#associatedtype.Value" class="type">Value</a>;
fn <a href="#tymethod.deserialize" class="fnname">deserialize</a>&lt;D&gt;(self, deserializer: D) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/de/trait.DeserializeSeed.html#associatedtype.Value" title="type serde::de::DeserializeSeed::Value">Value</a>, D::<a class="type" href="../../serde/trait.Deserializer.html#associatedtype.Error" title="type serde::Deserializer::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D: <a class="trait" href="../../serde/trait.Deserializer.html" title="trait serde::Deserializer">Deserializer</a>&lt;'de&gt;</span>;
}</pre></div><div class="docblock"><p><code>DeserializeSeed</code> is the stateful form of the <code>Deserialize</code> trait. If you
ever find yourself looking for a way to pass data into a <code>Deserialize</code> impl,
this trait is the way to do it.</p>
<p>As one example of stateful deserialization consider deserializing a JSON
array into an existing buffer. Using the <code>Deserialize</code> trait we could
deserialize a JSON array into a <code>Vec&lt;T&gt;</code> but it would be a freshly allocated
<code>Vec&lt;T&gt;</code>; there is no way for <code>Deserialize</code> to reuse a previously allocated
buffer. Using <code>DeserializeSeed</code> instead makes this possible as in the
example code below.</p>
<p>The canonical API for stateless deserialization looks like this:</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">fn</span> <span class="ident">func</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span>, <span class="ident">T</span>: <span class="ident">Deserialize</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span><span class="op">&gt;</span>() <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">T</span>, <span class="ident">Error</span><span class="op">&gt;</span></pre></div>
<p>Adjusting an API like this to support stateful deserialization is a matter
of accepting a seed as input:</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">fn</span> <span class="ident">func_seed</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span>, <span class="ident">T</span>: <span class="ident">DeserializeSeed</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span><span class="op">&gt;</span>(<span class="ident">seed</span>: <span class="ident">T</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">T</span>::<span class="ident">Value</span>, <span class="ident">Error</span><span class="op">&gt;</span></pre></div>
<p>In practice the majority of deserialization is stateless. An API expecting a
seed can be appeased by passing <code>std::marker::PhantomData</code> as a seed in the
case of stateless deserialization.</p>
<h1 id="lifetime" class="section-header"><a href="#lifetime">Lifetime</a></h1>
<p>The <code>'de</code> lifetime of this trait is the lifetime of data that may be
borrowed by <code>Self::Value</code> when deserialized. See the page <a href="https://serde.rs/lifetimes.html">Understanding
deserializer lifetimes</a> for a more detailed explanation of these lifetimes.</p>
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
<p>Suppose we have JSON that looks like <code>[[1, 2], [3, 4, 5], [6]]</code> and we need
to deserialize it into a flat representation like <code>vec![1, 2, 3, 4, 5, 6]</code>.
Allocating a brand new <code>Vec&lt;T&gt;</code> for each subarray would be slow. Instead we
would like to allocate a single <code>Vec&lt;T&gt;</code> and then deserialize each subarray
into it. This requires stateful deserialization using the <code>DeserializeSeed</code>
trait.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fmt</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">marker</span>::<span class="ident">PhantomData</span>;
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">de</span>::{<span class="ident">Deserialize</span>, <span class="ident">DeserializeSeed</span>, <span class="ident">Deserializer</span>, <span class="ident">SeqAccess</span>, <span class="ident">Visitor</span>};
<span class="comment">// A DeserializeSeed implementation that uses stateful deserialization to</span>
<span class="comment">// append array elements onto the end of an existing vector. The preexisting</span>
<span class="comment">// state (&quot;seed&quot;) in this case is the Vec&lt;T&gt;. The `deserialize` method of</span>
<span class="comment">// `ExtendVec` will be traversing the inner arrays of the JSON input and</span>
<span class="comment">// appending each integer into the existing Vec.</span>
<span class="kw">struct</span> <span class="ident">ExtendVec</span><span class="op">&lt;</span><span class="lifetime">&#39;a</span>, <span class="ident">T</span>: <span class="lifetime">&#39;a</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="lifetime">&#39;a</span> <span class="kw-2">mut</span> <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>);
<span class="kw">impl</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span>, <span class="lifetime">&#39;a</span>, <span class="ident">T</span><span class="op">&gt;</span> <span class="ident">DeserializeSeed</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span> <span class="kw">for</span> <span class="ident">ExtendVec</span><span class="op">&lt;</span><span class="lifetime">&#39;a</span>, <span class="ident">T</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">T</span>: <span class="ident">Deserialize</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="comment">// The return type of the `deserialize` method. This implementation</span>
<span class="comment">// appends onto an existing vector but does not create any new data</span>
<span class="comment">// structure, so the return type is ().</span>
<span class="kw">type</span> <span class="ident">Value</span> <span class="op">=</span> ();
<span class="kw">fn</span> <span class="ident">deserialize</span><span class="op">&lt;</span><span class="ident">D</span><span class="op">&gt;</span>(<span class="self">self</span>, <span class="ident">deserializer</span>: <span class="ident">D</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span>::<span class="ident">Value</span>, <span class="ident">D</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">D</span>: <span class="ident">Deserializer</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="comment">// Visitor implementation that will walk an inner array of the JSON</span>
<span class="comment">// input.</span>
<span class="kw">struct</span> <span class="ident">ExtendVecVisitor</span><span class="op">&lt;</span><span class="lifetime">&#39;a</span>, <span class="ident">T</span>: <span class="lifetime">&#39;a</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="lifetime">&#39;a</span> <span class="kw-2">mut</span> <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>);
<span class="kw">impl</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span>, <span class="lifetime">&#39;a</span>, <span class="ident">T</span><span class="op">&gt;</span> <span class="ident">Visitor</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span> <span class="kw">for</span> <span class="ident">ExtendVecVisitor</span><span class="op">&lt;</span><span class="lifetime">&#39;a</span>, <span class="ident">T</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">T</span>: <span class="ident">Deserialize</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="kw">type</span> <span class="ident">Value</span> <span class="op">=</span> ();
<span class="kw">fn</span> <span class="ident">expecting</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">formatter</span>: <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> {
<span class="macro">write</span><span class="macro">!</span>(<span class="ident">formatter</span>, <span class="string">&quot;an array of integers&quot;</span>)
}
<span class="kw">fn</span> <span class="ident">visit_seq</span><span class="op">&lt;</span><span class="ident">A</span><span class="op">&gt;</span>(<span class="self">self</span>, <span class="kw-2">mut</span> <span class="ident">seq</span>: <span class="ident">A</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span>(), <span class="ident">A</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">A</span>: <span class="ident">SeqAccess</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="comment">// Visit each element in the inner array and push it onto</span>
<span class="comment">// the existing vector.</span>
<span class="kw">while</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">elem</span>) <span class="op">=</span> <span class="ident">seq</span>.<span class="ident">next_element</span>()<span class="question-mark">?</span> {
<span class="self">self</span>.<span class="number">0</span>.<span class="ident">push</span>(<span class="ident">elem</span>);
}
<span class="prelude-val">Ok</span>(())
}
}
<span class="ident">deserializer</span>.<span class="ident">deserialize_seq</span>(<span class="ident">ExtendVecVisitor</span>(<span class="self">self</span>.<span class="number">0</span>))
}
}
<span class="comment">// Visitor implementation that will walk the outer array of the JSON input.</span>
<span class="kw">struct</span> <span class="ident">FlattenedVecVisitor</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>(<span class="ident">PhantomData</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>);
<span class="kw">impl</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span>, <span class="ident">T</span><span class="op">&gt;</span> <span class="ident">Visitor</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span> <span class="kw">for</span> <span class="ident">FlattenedVecVisitor</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">T</span>: <span class="ident">Deserialize</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="comment">// This Visitor constructs a single Vec&lt;T&gt; to hold the flattened</span>
<span class="comment">// contents of the inner arrays.</span>
<span class="kw">type</span> <span class="ident">Value</span> <span class="op">=</span> <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>;
<span class="kw">fn</span> <span class="ident">expecting</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">formatter</span>: <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> {
<span class="macro">write</span><span class="macro">!</span>(<span class="ident">formatter</span>, <span class="string">&quot;an array of arrays&quot;</span>)
}
<span class="kw">fn</span> <span class="ident">visit_seq</span><span class="op">&lt;</span><span class="ident">A</span><span class="op">&gt;</span>(<span class="self">self</span>, <span class="kw-2">mut</span> <span class="ident">seq</span>: <span class="ident">A</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>, <span class="ident">A</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">A</span>: <span class="ident">SeqAccess</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="comment">// Create a single Vec to hold the flattened contents.</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
<span class="comment">// Each iteration through this loop is one inner array.</span>
<span class="kw">while</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(()) <span class="op">=</span> <span class="ident">seq</span>.<span class="ident">next_element_seed</span>(<span class="ident">ExtendVec</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">vec</span>))<span class="question-mark">?</span> {
<span class="comment">// Nothing to do; inner array has been appended into `vec`.</span>
}
<span class="comment">// Return the finished vec.</span>
<span class="prelude-val">Ok</span>(<span class="ident">vec</span>)
}
}
<span class="kw">let</span> <span class="ident">visitor</span> <span class="op">=</span> <span class="ident">FlattenedVecVisitor</span>(<span class="ident">PhantomData</span>);
<span class="kw">let</span> <span class="ident">flattened</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">u64</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">deserializer</span>.<span class="ident">deserialize_seq</span>(<span class="ident">visitor</span>)<span class="question-mark">?</span>;</pre></div>
</div><h2 id="associated-types" class="small-section-header">Associated Types<a href="#associated-types" class="anchor"></a></h2><div class="methods"><h3 id="associatedtype.Value" class="method"><code>type <a href="#associatedtype.Value" class="type">Value</a></code><a class="srclink" href="../../src/serde/de/mod.rs.html#765" title="goto source code">[src]</a></h3><div class="docblock"><p>The type produced by using this seed.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.deserialize" class="method"><code>fn <a href="#tymethod.deserialize" class="fnname">deserialize</a>&lt;D&gt;(self, deserializer: D) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/de/trait.DeserializeSeed.html#associatedtype.Value" title="type serde::de::DeserializeSeed::Value">Value</a>, D::<a class="type" href="../../serde/trait.Deserializer.html#associatedtype.Error" title="type serde::Deserializer::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;D: <a class="trait" href="../../serde/trait.Deserializer.html" title="trait serde::Deserializer">Deserializer</a>&lt;'de&gt;,&nbsp;</span></code><a class="srclink" href="../../src/serde/de/mod.rs.html#769-771" title="goto source code">[src]</a></h3><div class="docblock"><p>Equivalent to the more common <code>Deserialize::deserialize</code> method, except
with some initial piece of data (the seed) passed in.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><h3 id="impl-DeserializeSeed%3C%27de%3E-for-PhantomData%3CT%3E" class="impl"><code class="in-band">impl&lt;'de, T&gt; <a class="trait" href="../../serde/de/trait.DeserializeSeed.html" title="trait serde::de::DeserializeSeed">DeserializeSeed</a>&lt;'de&gt; for <a class="struct" href="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomData.html" title="struct core::marker::PhantomData">PhantomData</a>&lt;T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Deserialize.html" title="trait serde::Deserialize">Deserialize</a>&lt;'de&gt;,&nbsp;</span></code><a href="#impl-DeserializeSeed%3C%27de%3E-for-PhantomData%3CT%3E" class="anchor"></a><a class="srclink" href="../../src/serde/de/mod.rs.html#774-787" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Value-1" class="type"><code>type <a href="#associatedtype.Value" class="type">Value</a> = T</code></h4><h4 id="method.deserialize" class="method hidden"><code>fn <a href="#method.deserialize" class="fnname">deserialize</a>&lt;D&gt;(self, deserializer: D) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, D::<a class="type" href="../../serde/trait.Deserializer.html#associatedtype.Error" title="type serde::Deserializer::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;D: <a class="trait" href="../../serde/trait.Deserializer.html" title="trait serde::Deserializer">Deserializer</a>&lt;'de&gt;,&nbsp;</span></code><a class="srclink" href="../../src/serde/de/mod.rs.html#781-786" title="goto source code">[src]</a></h4></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/de/trait.DeserializeSeed.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<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
+80
View File
@@ -0,0 +1,80 @@
<!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="The `Error` trait allows `Deserialize` implementations to create descriptive error messages belonging to the `Deserializer` against which they are currently running."><meta name="keywords" content="rust, rustlang, rust-lang, Error"><title>serde::de::Error - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait Error</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.custom">custom</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.invalid_type">invalid_type</a><a href="#method.invalid_value">invalid_value</a><a href="#method.invalid_length">invalid_length</a><a href="#method.unknown_variant">unknown_variant</a><a href="#method.unknown_field">unknown_field</a><a href="#method.missing_field">missing_field</a><a href="#method.duplicate_field">duplicate_field</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">de</a></p><div id="sidebar-vars" data-name="Error" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">de</a>::<wbr><a class="trait" href="">Error</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/de/mod.rs.html#297" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait Error: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">StdError</a> {
fn <a href="#tymethod.custom" class="fnname">custom</a>&lt;T&gt;(msg: T) -&gt; Self<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a></span>;
fn <a href="#method.invalid_type" class="fnname">invalid_type</a>(unexp: <a class="enum" href="../../serde/de/enum.Unexpected.html" title="enum serde::de::Unexpected">Unexpected</a>&lt;'_&gt;, exp: &amp;dyn <a class="trait" href="../../serde/de/trait.Expected.html" title="trait serde::de::Expected">Expected</a>) -&gt; Self { ... }
<div class="item-spacer"></div> fn <a href="#method.invalid_value" class="fnname">invalid_value</a>(unexp: <a class="enum" href="../../serde/de/enum.Unexpected.html" title="enum serde::de::Unexpected">Unexpected</a>&lt;'_&gt;, exp: &amp;dyn <a class="trait" href="../../serde/de/trait.Expected.html" title="trait serde::de::Expected">Expected</a>) -&gt; Self { ... }
<div class="item-spacer"></div> fn <a href="#method.invalid_length" class="fnname">invalid_length</a>(len: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, exp: &amp;dyn <a class="trait" href="../../serde/de/trait.Expected.html" title="trait serde::de::Expected">Expected</a>) -&gt; Self { ... }
<div class="item-spacer"></div> fn <a href="#method.unknown_variant" class="fnname">unknown_variant</a>(variant: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, expected: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'static [</a>&amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -&gt; Self { ... }
<div class="item-spacer"></div> fn <a href="#method.unknown_field" class="fnname">unknown_field</a>(field: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, expected: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'static [</a>&amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -&gt; Self { ... }
<div class="item-spacer"></div> fn <a href="#method.missing_field" class="fnname">missing_field</a>(field: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; Self { ... }
<div class="item-spacer"></div> fn <a href="#method.duplicate_field" class="fnname">duplicate_field</a>(field: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; Self { ... }
}</pre></div><div class="docblock"><p>The <code>Error</code> trait allows <code>Deserialize</code> implementations to create descriptive
error messages belonging to the <code>Deserializer</code> against which they are
currently running.</p>
<p>Every <code>Deserializer</code> declares an <code>Error</code> type that encompasses both
general-purpose deserialization errors as well as errors specific to the
particular deserialization format. For example the <code>Error</code> type of
<code>serde_json</code> can represent errors like an invalid JSON escape sequence or an
unterminated string literal, in addition to the error cases that are part of
this trait.</p>
<p>Most deserializers should only need to provide the <code>Error::custom</code> method
and inherit the default behavior for the other methods.</p>
<h1 id="example-implementation" class="section-header"><a href="#example-implementation">Example implementation</a></h1>
<p>The <a href="https://serde.rs/data-format.html">example data format</a> presented on the website shows an error
type appropriate for a basic JSON data format.</p>
</div><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.custom" class="method"><code>fn <a href="#tymethod.custom" class="fnname">custom</a>&lt;T&gt;(msg: T) -&gt; Self <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/de/mod.rs.html#297" title="goto source code">[src]</a></h3><div class="docblock"><p>Raised when there is general error when deserializing a type.</p>
<p>The message should not be capitalized and should not end with a period.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">de</span>::{<span class="self">self</span>, <span class="ident">Deserialize</span>, <span class="ident">Deserializer</span>};
<span class="kw">impl</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span> <span class="ident">Deserialize</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span> <span class="kw">for</span> <span class="ident">IpAddr</span> {
<span class="kw">fn</span> <span class="ident">deserialize</span><span class="op">&lt;</span><span class="ident">D</span><span class="op">&gt;</span>(<span class="ident">deserializer</span>: <span class="ident">D</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span>, <span class="ident">D</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">D</span>: <span class="ident">Deserializer</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">deserialize</span>(<span class="ident">deserializer</span>)<span class="question-mark">?</span>;
<span class="ident">s</span>.<span class="ident">parse</span>().<span class="ident">map_err</span>(<span class="ident">de</span>::<span class="ident">Error</span>::<span class="ident">custom</span>)
}
}</pre></div>
</div></div><span class="loading-content">Loading content...</span><h2 id="provided-methods" class="small-section-header">Provided methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><h3 id="method.invalid_type" class="method"><code>fn <a href="#method.invalid_type" class="fnname">invalid_type</a>(unexp: <a class="enum" href="../../serde/de/enum.Unexpected.html" title="enum serde::de::Unexpected">Unexpected</a>&lt;'_&gt;, exp: &amp;dyn <a class="trait" href="../../serde/de/trait.Expected.html" title="trait serde::de::Expected">Expected</a>) -&gt; Self</code><a class="srclink" href="../../src/serde/de/mod.rs.html#297" title="goto source code">[src]</a></h3><div class="docblock"><p>Raised when a <code>Deserialize</code> receives a type different from what it was
expecting.</p>
<p>The <code>unexp</code> argument provides information about what type was received.
This is the type that was present in the input file or other source data
of the Deserializer.</p>
<p>The <code>exp</code> argument provides information about what type was being
expected. This is the type that is written in the program.</p>
<p>For example if we try to deserialize a String out of a JSON file
containing an integer, the unexpected type is the integer and the
expected type is the string.</p>
</div><h3 id="method.invalid_value" class="method"><code>fn <a href="#method.invalid_value" class="fnname">invalid_value</a>(unexp: <a class="enum" href="../../serde/de/enum.Unexpected.html" title="enum serde::de::Unexpected">Unexpected</a>&lt;'_&gt;, exp: &amp;dyn <a class="trait" href="../../serde/de/trait.Expected.html" title="trait serde::de::Expected">Expected</a>) -&gt; Self</code><a class="srclink" href="../../src/serde/de/mod.rs.html#297" title="goto source code">[src]</a></h3><div class="docblock"><p>Raised when a <code>Deserialize</code> receives a value of the right type but that
is wrong for some other reason.</p>
<p>The <code>unexp</code> argument provides information about what value was received.
This is the value that was present in the input file or other source
data of the Deserializer.</p>
<p>The <code>exp</code> argument provides information about what value was being
expected. This is the type that is written in the program.</p>
<p>For example if we try to deserialize a String out of some binary data
that is not valid UTF-8, the unexpected value is the bytes and the
expected value is a string.</p>
</div><h3 id="method.invalid_length" class="method"><code>fn <a href="#method.invalid_length" class="fnname">invalid_length</a>(len: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, exp: &amp;dyn <a class="trait" href="../../serde/de/trait.Expected.html" title="trait serde::de::Expected">Expected</a>) -&gt; Self</code><a class="srclink" href="../../src/serde/de/mod.rs.html#297" title="goto source code">[src]</a></h3><div class="docblock"><p>Raised when deserializing a sequence or map and the input data contains
too many or too few elements.</p>
<p>The <code>len</code> argument is the number of elements encountered. The sequence
or map may have expected more arguments or fewer arguments.</p>
<p>The <code>exp</code> argument provides information about what data was being
expected. For example <code>exp</code> might say that a tuple of size 6 was
expected.</p>
</div><h3 id="method.unknown_variant" class="method"><code>fn <a href="#method.unknown_variant" class="fnname">unknown_variant</a>(variant: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, expected: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'static [</a>&amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -&gt; Self</code><a class="srclink" href="../../src/serde/de/mod.rs.html#297" title="goto source code">[src]</a></h3><div class="docblock"><p>Raised when a <code>Deserialize</code> enum type received a variant with an
unrecognized name.</p>
</div><h3 id="method.unknown_field" class="method"><code>fn <a href="#method.unknown_field" class="fnname">unknown_field</a>(field: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, expected: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'static [</a>&amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -&gt; Self</code><a class="srclink" href="../../src/serde/de/mod.rs.html#297" title="goto source code">[src]</a></h3><div class="docblock"><p>Raised when a <code>Deserialize</code> struct type received a field with an
unrecognized name.</p>
</div><h3 id="method.missing_field" class="method"><code>fn <a href="#method.missing_field" class="fnname">missing_field</a>(field: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; Self</code><a class="srclink" href="../../src/serde/de/mod.rs.html#297" title="goto source code">[src]</a></h3><div class="docblock"><p>Raised when a <code>Deserialize</code> struct type expected to receive a required
field with a particular name but that field was not present in the
input.</p>
</div><h3 id="method.duplicate_field" class="method"><code>fn <a href="#method.duplicate_field" class="fnname">duplicate_field</a>(field: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; Self</code><a class="srclink" href="../../src/serde/de/mod.rs.html#297" title="goto source code">[src]</a></h3><div class="docblock"><p>Raised when a <code>Deserialize</code> struct type received more than one of the
same field.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-Error" class="impl"><code class="in-band">impl <a class="trait" href="../../serde/de/trait.Error.html" title="trait serde::de::Error">Error</a> for <a class="struct" href="../../serde/de/value/struct.Error.html" title="struct serde::de::value::Error">Error</a></code><a href="#impl-Error" class="anchor"></a><a class="srclink" href="../../src/serde/de/value.rs.html#61-82" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.custom" class="method hidden"><code>fn <a href="#method.custom" class="fnname">custom</a>&lt;T&gt;(msg: T) -&gt; Self <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/de/value.rs.html#64-71" title="goto source code">[src]</a></h4></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/de/trait.Error.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
+32
View File
@@ -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="`Expected` represents an explanation of what data a `Visitor` was expecting to receive."><meta name="keywords" content="rust, rustlang, rust-lang, Expected"><title>serde::de::Expected - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait Expected</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.fmt">fmt</a></div><a class="sidebar-title" href="#foreign-impls">Implementations on Foreign Types</a><div class="sidebar-links"><a href="#impl-Expected-for-%26%27a%20str">&amp;&#39;a str</a></div><a class="sidebar-title" href="#trait-implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Display">Display</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">de</a></p><div id="sidebar-vars" data-name="Expected" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">de</a>::<wbr><a class="trait" href="">Expected</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/de/mod.rs.html#469-473" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait Expected {
fn <a href="#tymethod.fmt" class="fnname">fmt</a>(&amp;self, formatter: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a>;
}</pre></div><div class="docblock"><p><code>Expected</code> represents an explanation of what data a <code>Visitor</code> was expecting
to receive.</p>
<p>This is used as an argument to the <code>invalid_type</code>, <code>invalid_value</code>, and
<code>invalid_length</code> methods of the <code>Error</code> trait to build error messages. The
message should be a noun or noun phrase that completes the sentence “This
Visitor expects to receive …”, for example the message could be “an
integer between 0 and 64”. The message should not be capitalized and should
not end with a period.</p>
<p>Within the context of a <code>Visitor</code> implementation, the <code>Visitor</code> itself
(<code>&amp;self</code>) is an implementation of this trait.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">fn</span> <span class="ident">visit_bool</span><span class="op">&lt;</span><span class="ident">E</span><span class="op">&gt;</span>(<span class="self">self</span>, <span class="ident">v</span>: <span class="ident">bool</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span>::<span class="ident">Value</span>, <span class="ident">E</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">E</span>: <span class="ident">de</span>::<span class="ident">Error</span>,
{
<span class="prelude-val">Err</span>(<span class="ident">de</span>::<span class="ident">Error</span>::<span class="ident">invalid_type</span>(<span class="ident">Unexpected</span>::<span class="ident">Bool</span>(<span class="ident">v</span>), <span class="kw-2">&amp;</span><span class="self">self</span>))
}</pre></div>
<p>Outside of a <code>Visitor</code>, <code>&amp;&quot;...&quot;</code> can be used.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">return</span> <span class="prelude-val">Err</span>(<span class="ident">de</span>::<span class="ident">Error</span>::<span class="ident">invalid_type</span>(<span class="ident">Unexpected</span>::<span class="ident">Bool</span>(<span class="ident">v</span>), <span class="kw-2">&amp;</span><span class="string">&quot;a negative integer&quot;</span>));</pre></div>
</div><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.fmt" class="method"><code>fn <a href="#tymethod.fmt" class="fnname">fmt</a>(&amp;self, formatter: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code><a class="srclink" href="../../src/serde/de/mod.rs.html#472" title="goto source code">[src]</a></h3><div class="docblock"><p>Format an explanation of what data was being expected. Same signature as
the <code>Display</code> and <code>Debug</code> traits.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><h3 id="impl-Display" class="impl"><code class="in-band">impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> for dyn <a class="trait" href="../../serde/de/trait.Expected.html" title="trait serde::de::Expected">Expected</a> + 'a</code><a href="#impl-Display" class="anchor"></a><a class="srclink" href="../../src/serde/de/mod.rs.html#490-494" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.fmt" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt" class="fnname">fmt</a>(&amp;self, formatter: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code><a class="srclink" href="../../src/serde/de/mod.rs.html#491-493" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt">Read more</a></p>
</div></div></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><h3 id="impl-Expected-for-%26%27a%20str" class="impl"><code class="in-band">impl&lt;'a&gt; <a class="trait" href="../../serde/de/trait.Expected.html" title="trait serde::de::Expected">Expected</a> for &amp;'a <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a></code><a href="#impl-Expected-for-%26%27a%20str" class="anchor"></a><a class="srclink" href="../../src/serde/de/mod.rs.html#484-488" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.fmt-1" class="method hidden"><code>fn <a href="#method.fmt" class="fnname">fmt</a>(&amp;self, formatter: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code><a class="srclink" href="../../src/serde/de/mod.rs.html#485-487" title="goto source code">[src]</a></h4></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-Expected" class="impl"><code class="in-band">impl&lt;'de, T&gt; <a class="trait" href="../../serde/de/trait.Expected.html" title="trait serde::de::Expected">Expected</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/de/trait.Visitor.html" title="trait serde::de::Visitor">Visitor</a>&lt;'de&gt;,&nbsp;</span></code><a href="#impl-Expected" class="anchor"></a><a class="srclink" href="../../src/serde/de/mod.rs.html#475-482" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.fmt-2" class="method hidden"><code>fn <a href="#method.fmt-2" class="fnname">fmt</a>(&amp;self, formatter: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code><a class="srclink" href="../../src/serde/de/mod.rs.html#479-481" title="goto source code">[src]</a></h4></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/de/trait.Expected.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<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
File diff suppressed because one or more lines are too long
+91
View File
@@ -0,0 +1,91 @@
<!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="`VariantAccess` is a visitor that is created by the `Deserializer` and passed to the `Deserialize` to deserialize the content of a particular enum variant."><meta name="keywords" content="rust, rustlang, rust-lang, VariantAccess"><title>serde::de::VariantAccess - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait VariantAccess</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Error">Error</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.struct_variant">struct_variant</a><a href="#tymethod.unit_variant">unit_variant</a><a href="#tymethod.newtype_variant_seed">newtype_variant_seed</a><a href="#tymethod.tuple_variant">tuple_variant</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.newtype_variant">newtype_variant</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">de</a></p><div id="sidebar-vars" data-name="VariantAccess" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">de</a>::<wbr><a class="trait" href="">VariantAccess</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/de/mod.rs.html#2004-2200" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait VariantAccess&lt;'de&gt;: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/de/trait.Error.html" title="trait serde::de::Error">Error</a>;
fn <a href="#tymethod.unit_variant" class="fnname">unit_variant</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/de/trait.VariantAccess.html#associatedtype.Error" title="type serde::de::VariantAccess::Error">Error</a>&gt;;
<div class="item-spacer"></div> fn <a href="#tymethod.newtype_variant_seed" class="fnname">newtype_variant_seed</a>&lt;T&gt;(self, seed: T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T::<a class="type" href="../../serde/de/trait.DeserializeSeed.html#associatedtype.Value" title="type serde::de::DeserializeSeed::Value">Value</a>, Self::<a class="type" href="../../serde/de/trait.VariantAccess.html#associatedtype.Error" title="type serde::de::VariantAccess::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/de/trait.DeserializeSeed.html" title="trait serde::de::DeserializeSeed">DeserializeSeed</a>&lt;'de&gt;</span>;
<div class="item-spacer"></div> fn <a href="#tymethod.tuple_variant" class="fnname">tuple_variant</a>&lt;V&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;len: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;visitor: V<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;V::<a class="type" href="../../serde/de/trait.Visitor.html#associatedtype.Value" title="type serde::de::Visitor::Value">Value</a>, Self::<a class="type" href="../../serde/de/trait.VariantAccess.html#associatedtype.Error" title="type serde::de::VariantAccess::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../serde/de/trait.Visitor.html" title="trait serde::de::Visitor">Visitor</a>&lt;'de&gt;</span>;
<div class="item-spacer"></div> fn <a href="#tymethod.struct_variant" class="fnname">struct_variant</a>&lt;V&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fields: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'static [</a>&amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;visitor: V<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;V::<a class="type" href="../../serde/de/trait.Visitor.html#associatedtype.Value" title="type serde::de::Visitor::Value">Value</a>, Self::<a class="type" href="../../serde/de/trait.VariantAccess.html#associatedtype.Error" title="type serde::de::VariantAccess::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../serde/de/trait.Visitor.html" title="trait serde::de::Visitor">Visitor</a>&lt;'de&gt;</span>;
fn <a href="#method.newtype_variant" class="fnname">newtype_variant</a>&lt;T&gt;(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, Self::<a class="type" href="../../serde/de/trait.VariantAccess.html#associatedtype.Error" title="type serde::de::VariantAccess::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Deserialize.html" title="trait serde::Deserialize">Deserialize</a>&lt;'de&gt;</span>,
{ ... }
}</pre></div><div class="docblock"><p><code>VariantAccess</code> is a visitor that is created by the <code>Deserializer</code> and
passed to the <code>Deserialize</code> to deserialize the content of a particular enum
variant.</p>
<h1 id="lifetime" class="section-header"><a href="#lifetime">Lifetime</a></h1>
<p>The <code>'de</code> lifetime of this trait is the lifetime of data that may be
borrowed by the deserialized enum variant. See the page <a href="https://serde.rs/lifetimes.html">Understanding
deserializer lifetimes</a> for a more detailed explanation of these lifetimes.</p>
<h1 id="example-implementation" class="section-header"><a href="#example-implementation">Example implementation</a></h1>
<p>The <a href="https://serde.rs/data-format.html">example data format</a> presented on the website demonstrates an
implementation of <code>VariantAccess</code> for a basic JSON data format.</p>
</div><h2 id="associated-types" class="small-section-header">Associated Types<a href="#associated-types" class="anchor"></a></h2><div class="methods"><h3 id="associatedtype.Error" class="method"><code>type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/de/trait.Error.html" title="trait serde::de::Error">Error</a></code><a class="srclink" href="../../src/serde/de/mod.rs.html#2007" title="goto source code">[src]</a></h3><div class="docblock"><p>The error type that can be returned if some error occurs during
deserialization. Must match the error type of our <code>EnumAccess</code>.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.unit_variant" class="method"><code>fn <a href="#tymethod.unit_variant" class="fnname">unit_variant</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/de/trait.VariantAccess.html#associatedtype.Error" title="type serde::de::VariantAccess::Error">Error</a>&gt;</code><a class="srclink" href="../../src/serde/de/mod.rs.html#2044" title="goto source code">[src]</a></h3><div class="docblock"><p>Called when deserializing a variant with no values.</p>
<p>If the data contains a different type of variant, the following
<code>invalid_type</code> error should be constructed:</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">fn</span> <span class="ident">unit_variant</span>(<span class="self">self</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span>(), <span class="self">Self</span>::<span class="ident">Error</span><span class="op">&gt;</span> {
<span class="comment">// What the data actually contained; suppose it is a tuple variant.</span>
<span class="kw">let</span> <span class="ident">unexp</span> <span class="op">=</span> <span class="ident">Unexpected</span>::<span class="ident">TupleVariant</span>;
<span class="prelude-val">Err</span>(<span class="ident">de</span>::<span class="ident">Error</span>::<span class="ident">invalid_type</span>(<span class="ident">unexp</span>, <span class="kw-2">&amp;</span><span class="string">&quot;unit variant&quot;</span>))
}</pre></div>
</div><h3 id="tymethod.newtype_variant_seed" class="method"><code>fn <a href="#tymethod.newtype_variant_seed" class="fnname">newtype_variant_seed</a>&lt;T&gt;(self, seed: T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T::<a class="type" href="../../serde/de/trait.DeserializeSeed.html#associatedtype.Value" title="type serde::de::DeserializeSeed::Value">Value</a>, Self::<a class="type" href="../../serde/de/trait.VariantAccess.html#associatedtype.Error" title="type serde::de::VariantAccess::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/de/trait.DeserializeSeed.html" title="trait serde::de::DeserializeSeed">DeserializeSeed</a>&lt;'de&gt;,&nbsp;</span></code><a class="srclink" href="../../src/serde/de/mod.rs.html#2086-2088" title="goto source code">[src]</a></h3><div class="docblock"><p>Called when deserializing a variant with a single value.</p>
<p><code>Deserialize</code> implementations should typically use
<code>VariantAccess::newtype_variant</code> instead.</p>
<p>If the data contains a different type of variant, the following
<code>invalid_type</code> error should be constructed:</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">fn</span> <span class="ident">newtype_variant_seed</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>(<span class="self">self</span>, <span class="ident">_seed</span>: <span class="ident">T</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">T</span>::<span class="ident">Value</span>, <span class="self">Self</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">T</span>: <span class="ident">DeserializeSeed</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="comment">// What the data actually contained; suppose it is a unit variant.</span>
<span class="kw">let</span> <span class="ident">unexp</span> <span class="op">=</span> <span class="ident">Unexpected</span>::<span class="ident">UnitVariant</span>;
<span class="prelude-val">Err</span>(<span class="ident">de</span>::<span class="ident">Error</span>::<span class="ident">invalid_type</span>(<span class="ident">unexp</span>, <span class="kw-2">&amp;</span><span class="string">&quot;newtype variant&quot;</span>))
}</pre></div>
</div><h3 id="tymethod.tuple_variant" class="method"><code>fn <a href="#tymethod.tuple_variant" class="fnname">tuple_variant</a>&lt;V&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;len: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;visitor: V<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;V::<a class="type" href="../../serde/de/trait.Visitor.html#associatedtype.Value" title="type serde::de::Visitor::Value">Value</a>, Self::<a class="type" href="../../serde/de/trait.VariantAccess.html#associatedtype.Error" title="type serde::de::VariantAccess::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../serde/de/trait.Visitor.html" title="trait serde::de::Visitor">Visitor</a>&lt;'de&gt;,&nbsp;</span></code><a class="srclink" href="../../src/serde/de/mod.rs.html#2146-2148" title="goto source code">[src]</a></h3><div class="docblock"><p>Called when deserializing a tuple-like variant.</p>
<p>The <code>len</code> is the number of fields expected in the tuple variant.</p>
<p>If the data contains a different type of variant, the following
<code>invalid_type</code> error should be constructed:</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">fn</span> <span class="ident">tuple_variant</span><span class="op">&lt;</span><span class="ident">V</span><span class="op">&gt;</span>(
<span class="self">self</span>,
<span class="ident">_len</span>: <span class="ident">usize</span>,
<span class="ident">_visitor</span>: <span class="ident">V</span>,
) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">V</span>::<span class="ident">Value</span>, <span class="self">Self</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">V</span>: <span class="ident">Visitor</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="comment">// What the data actually contained; suppose it is a unit variant.</span>
<span class="kw">let</span> <span class="ident">unexp</span> <span class="op">=</span> <span class="ident">Unexpected</span>::<span class="ident">UnitVariant</span>;
<span class="prelude-val">Err</span>(<span class="ident">de</span>::<span class="ident">Error</span>::<span class="ident">invalid_type</span>(<span class="ident">unexp</span>, <span class="kw-2">&amp;</span><span class="string">&quot;tuple variant&quot;</span>))
}</pre></div>
</div><h3 id="tymethod.struct_variant" class="method"><code>fn <a href="#tymethod.struct_variant" class="fnname">struct_variant</a>&lt;V&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;fields: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'static [</a>&amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;visitor: V<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;V::<a class="type" href="../../serde/de/trait.Visitor.html#associatedtype.Value" title="type serde::de::Visitor::Value">Value</a>, Self::<a class="type" href="../../serde/de/trait.VariantAccess.html#associatedtype.Error" title="type serde::de::VariantAccess::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../serde/de/trait.Visitor.html" title="trait serde::de::Visitor">Visitor</a>&lt;'de&gt;,&nbsp;</span></code><a class="srclink" href="../../src/serde/de/mod.rs.html#2193-2199" title="goto source code">[src]</a></h3><div class="docblock"><p>Called when deserializing a struct-like variant.</p>
<p>The <code>fields</code> are the names of the fields of the struct variant.</p>
<p>If the data contains a different type of variant, the following
<code>invalid_type</code> error should be constructed:</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">fn</span> <span class="ident">struct_variant</span><span class="op">&lt;</span><span class="ident">V</span><span class="op">&gt;</span>(
<span class="self">self</span>,
<span class="ident">_fields</span>: <span class="kw-2">&amp;</span><span class="lifetime">&#39;static</span> [<span class="kw-2">&amp;</span><span class="lifetime">&#39;static</span> <span class="ident">str</span>],
<span class="ident">_visitor</span>: <span class="ident">V</span>,
) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">V</span>::<span class="ident">Value</span>, <span class="self">Self</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">V</span>: <span class="ident">Visitor</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="comment">// What the data actually contained; suppose it is a unit variant.</span>
<span class="kw">let</span> <span class="ident">unexp</span> <span class="op">=</span> <span class="ident">Unexpected</span>::<span class="ident">UnitVariant</span>;
<span class="prelude-val">Err</span>(<span class="ident">de</span>::<span class="ident">Error</span>::<span class="ident">invalid_type</span>(<span class="ident">unexp</span>, <span class="kw-2">&amp;</span><span class="string">&quot;struct variant&quot;</span>))
}</pre></div>
</div></div><span class="loading-content">Loading content...</span><h2 id="provided-methods" class="small-section-header">Provided methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><h3 id="method.newtype_variant" class="method"><code>fn <a href="#method.newtype_variant" class="fnname">newtype_variant</a>&lt;T&gt;(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, Self::<a class="type" href="../../serde/de/trait.VariantAccess.html#associatedtype.Error" title="type serde::de::VariantAccess::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Deserialize.html" title="trait serde::Deserialize">Deserialize</a>&lt;'de&gt;,&nbsp;</span></code><a class="srclink" href="../../src/serde/de/mod.rs.html#2096-2101" title="goto source code">[src]</a></h3><div class="docblock"><p>Called when deserializing a variant with a single value.</p>
<p>This method exists as a convenience for <code>Deserialize</code> implementations.
<code>VariantAccess</code> implementations should not override the default
behavior.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/de/trait.VariantAccess.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<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
+73
View File
@@ -0,0 +1,73 @@
<!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="Building blocks for deserializing basic values using the `IntoDeserializer` trait."><meta name="keywords" content="rust, rustlang, rust-lang, value"><title>serde::de::value - 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">&#9776;</div><a href='../../../serde/index.html'><div class='logo-container rust-logo'><img src='../../../rust-logo.png' alt='logo'></div></a><p class="location">Module value</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li></ul></div><p class="location"><a href="../../index.html">serde</a>::<wbr><a href="../index.html">de</a></p><div id="sidebar-vars" data-name="value" data-ty="mod" 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" 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="in-band">Module <a href="../../index.html">serde</a>::<wbr><a href="../index.html">de</a>::<wbr><a class="mod" href="">value</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../../src/serde/de/value.rs.html#1-1635" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Building blocks for deserializing basic values using the <code>IntoDeserializer</code>
trait.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">str</span>::<span class="ident">FromStr</span>;
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">Deserialize</span>;
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">de</span>::{<span class="ident">value</span>, <span class="ident">IntoDeserializer</span>};
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Deserialize</span>)]</span>
<span class="kw">enum</span> <span class="ident">Setting</span> {
<span class="ident">On</span>,
<span class="ident">Off</span>,
}
<span class="kw">impl</span> <span class="ident">FromStr</span> <span class="kw">for</span> <span class="ident">Setting</span> {
<span class="kw">type</span> <span class="prelude-val">Err</span> <span class="op">=</span> <span class="ident">value</span>::<span class="ident">Error</span>;
<span class="kw">fn</span> <span class="ident">from_str</span>(<span class="ident">s</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span>, <span class="self">Self</span>::<span class="prelude-val">Err</span><span class="op">&gt;</span> {
<span class="self">Self</span>::<span class="ident">deserialize</span>(<span class="ident">s</span>.<span class="ident">into_deserializer</span>())
}
}</pre></div>
</div><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
<table><tr class="module-item"><td><a class="struct" href="struct.BoolDeserializer.html" title="serde::de::value::BoolDeserializer struct">BoolDeserializer</a></td><td class="docblock-short"><p>A deserializer holding
a <code>bool</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.BorrowedBytesDeserializer.html" title="serde::de::value::BorrowedBytesDeserializer struct">BorrowedBytesDeserializer</a></td><td class="docblock-short"><p>A deserializer holding a <code>&amp;[u8]</code> with a lifetime tied to another
deserializer. Always calls <a href="../../../serde/de/trait.Visitor.html#method.visit_borrowed_bytes" title="Visitor::visit_borrowed_bytes"><code>Visitor::visit_borrowed_bytes</code></a>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.BorrowedStrDeserializer.html" title="serde::de::value::BorrowedStrDeserializer struct">BorrowedStrDeserializer</a></td><td class="docblock-short"><p>A deserializer holding a <code>&amp;str</code> with a lifetime tied to another
deserializer.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.BytesDeserializer.html" title="serde::de::value::BytesDeserializer struct">BytesDeserializer</a></td><td class="docblock-short"><p>A deserializer holding a <code>&amp;[u8]</code>. Always calls <a href="../../../serde/de/trait.Visitor.html#method.visit_bytes" title="Visitor::visit_bytes"><code>Visitor::visit_bytes</code></a>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.CharDeserializer.html" title="serde::de::value::CharDeserializer struct">CharDeserializer</a></td><td class="docblock-short"><p>A deserializer holding
a <code>char</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.CowStrDeserializer.html" title="serde::de::value::CowStrDeserializer struct">CowStrDeserializer</a></td><td class="docblock-short"><p>A deserializer holding a <code>Cow&lt;str&gt;</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.Error.html" title="serde::de::value::Error struct">Error</a></td><td class="docblock-short"><p>A minimal representation of all possible errors that can occur using the
<code>IntoDeserializer</code> trait.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.F32Deserializer.html" title="serde::de::value::F32Deserializer struct">F32Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
an <code>f32</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.F64Deserializer.html" title="serde::de::value::F64Deserializer struct">F64Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
an <code>f64</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.I8Deserializer.html" title="serde::de::value::I8Deserializer struct">I8Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
an <code>i8</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.I16Deserializer.html" title="serde::de::value::I16Deserializer struct">I16Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
an <code>i16</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.I32Deserializer.html" title="serde::de::value::I32Deserializer struct">I32Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
an <code>i32</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.I64Deserializer.html" title="serde::de::value::I64Deserializer struct">I64Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
an <code>i64</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.I128Deserializer.html" title="serde::de::value::I128Deserializer struct">I128Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
an <code>i128</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.IsizeDeserializer.html" title="serde::de::value::IsizeDeserializer struct">IsizeDeserializer</a></td><td class="docblock-short"><p>A deserializer holding
an <code>isize</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.MapAccessDeserializer.html" title="serde::de::value::MapAccessDeserializer struct">MapAccessDeserializer</a></td><td class="docblock-short"><p>A deserializer holding a <code>MapAccess</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.MapDeserializer.html" title="serde::de::value::MapDeserializer struct">MapDeserializer</a></td><td class="docblock-short"><p>A deserializer that iterates over a map.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SeqAccessDeserializer.html" title="serde::de::value::SeqAccessDeserializer struct">SeqAccessDeserializer</a></td><td class="docblock-short"><p>A deserializer holding a <code>SeqAccess</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.SeqDeserializer.html" title="serde::de::value::SeqDeserializer struct">SeqDeserializer</a></td><td class="docblock-short"><p>A deserializer that iterates over a sequence.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.StrDeserializer.html" title="serde::de::value::StrDeserializer struct">StrDeserializer</a></td><td class="docblock-short"><p>A deserializer holding a <code>&amp;str</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.StringDeserializer.html" title="serde::de::value::StringDeserializer struct">StringDeserializer</a></td><td class="docblock-short"><p>A deserializer holding a <code>String</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.U8Deserializer.html" title="serde::de::value::U8Deserializer struct">U8Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
a <code>u8</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.U16Deserializer.html" title="serde::de::value::U16Deserializer struct">U16Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
a <code>u16</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.U32Deserializer.html" title="serde::de::value::U32Deserializer struct">U32Deserializer</a></td><td class="docblock-short"><p>A deserializer holding a <code>u32</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.U64Deserializer.html" title="serde::de::value::U64Deserializer struct">U64Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
a <code>u64</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.U128Deserializer.html" title="serde::de::value::U128Deserializer struct">U128Deserializer</a></td><td class="docblock-short"><p>A deserializer holding
a <code>u128</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.UnitDeserializer.html" title="serde::de::value::UnitDeserializer struct">UnitDeserializer</a></td><td class="docblock-short"><p>A deserializer holding a <code>()</code>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.UsizeDeserializer.html" title="serde::de::value::UsizeDeserializer struct">UsizeDeserializer</a></td><td class="docblock-short"><p>A deserializer holding
a <code>usize</code>.</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="serde"></div>
<script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html>
+1
View File
@@ -0,0 +1 @@
initSidebarItems({"struct":[["BoolDeserializer","A deserializer holding a `bool`."],["BorrowedBytesDeserializer","A deserializer holding a `&[u8]` with a lifetime tied to another deserializer. Always calls [`Visitor::visit_borrowed_bytes`]."],["BorrowedStrDeserializer","A deserializer holding a `&str` with a lifetime tied to another deserializer."],["BytesDeserializer","A deserializer holding a `&[u8]`. Always calls [`Visitor::visit_bytes`]."],["CharDeserializer","A deserializer holding a `char`."],["CowStrDeserializer","A deserializer holding a `Cow<str>`."],["Error","A minimal representation of all possible errors that can occur using the `IntoDeserializer` trait."],["F32Deserializer","A deserializer holding an `f32`."],["F64Deserializer","A deserializer holding an `f64`."],["I128Deserializer","A deserializer holding an `i128`."],["I16Deserializer","A deserializer holding an `i16`."],["I32Deserializer","A deserializer holding an `i32`."],["I64Deserializer","A deserializer holding an `i64`."],["I8Deserializer","A deserializer holding an `i8`."],["IsizeDeserializer","A deserializer holding an `isize`."],["MapAccessDeserializer","A deserializer holding a `MapAccess`."],["MapDeserializer","A deserializer that iterates over a map."],["SeqAccessDeserializer","A deserializer holding a `SeqAccess`."],["SeqDeserializer","A deserializer that iterates over a sequence."],["StrDeserializer","A deserializer holding a `&str`."],["StringDeserializer","A deserializer holding a `String`."],["U128Deserializer","A deserializer holding a `u128`."],["U16Deserializer","A deserializer holding a `u16`."],["U32Deserializer","A deserializer holding a `u32`."],["U64Deserializer","A deserializer holding a `u64`."],["U8Deserializer","A deserializer holding a `u8`."],["UnitDeserializer","A deserializer holding a `()`."],["UsizeDeserializer","A deserializer holding a `usize`."]]});
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
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
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
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
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
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
+74
View File
@@ -0,0 +1,74 @@
<!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="Serde"><meta name="keywords" content="rust, rustlang, rust-lang, serde"><title>serde - 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">&#9776;</div><a href='../serde/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Crate serde</p><div class="block version"><p>Version 1.0.124</p></div><div class="sidebar-elems"><a id="all-types" href="all.html"><p>See all serde's items</p></a><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li><li><a href="#traits">Traits</a></li></ul></div><p class="location"></p><div id="sidebar-vars" data-name="serde" data-ty="mod" data-relpath="../"></div></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="in-band">Crate <a class="mod" href="">serde</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../src/serde/lib.rs.html#1-297" title="goto source code">[src]</a></span></h1><div class="docblock"><h1 id="serde" class="section-header"><a href="#serde">Serde</a></h1>
<p>Serde is a framework for <em><strong>ser</strong></em>ializing and <em><strong>de</strong></em>serializing Rust data
structures efficiently and generically.</p>
<p>The Serde ecosystem consists of data structures that know how to serialize
and deserialize themselves along with data formats that know how to
serialize and deserialize other things. Serde provides the layer by which
these two groups interact with each other, allowing any supported data
structure to be serialized and deserialized using any supported data format.</p>
<p>See the Serde website <a href="https://serde.rs/">https://serde.rs/</a> for additional documentation and
usage examples.</p>
<h2 id="design" class="section-header"><a href="#design">Design</a></h2>
<p>Where many other languages rely on runtime reflection for serializing data,
Serde is instead built on Rusts powerful trait system. A data structure
that knows how to serialize and deserialize itself is one that implements
Serdes <code>Serialize</code> and <code>Deserialize</code> traits (or uses Serdes derive
attribute to automatically generate implementations at compile time). This
avoids any overhead of reflection or runtime type information. In fact in
many situations the interaction between data structure and data format can
be completely optimized away by the Rust compiler, leaving Serde
serialization to perform the same speed as a handwritten serializer for the
specific selection of data structure and data format.</p>
<h2 id="data-formats" class="section-header"><a href="#data-formats">Data formats</a></h2>
<p>The following is a partial list of data formats that have been implemented
for Serde by the community.</p>
<ul>
<li><a href="https://github.com/serde-rs/json">JSON</a>, the ubiquitous JavaScript Object Notation used by many HTTP APIs.</li>
<li><a href="https://github.com/servo/bincode">Bincode</a>, a compact binary format
used for IPC within the Servo rendering engine.</li>
<li><a href="https://github.com/pyfisch/cbor">CBOR</a>, a Concise Binary Object Representation designed for small message
size without the need for version negotiation.</li>
<li><a href="https://github.com/dtolnay/serde-yaml">YAML</a>, a self-proclaimed human-friendly configuration language that aint
markup language.</li>
<li><a href="https://github.com/3Hren/msgpack-rust">MessagePack</a>, an efficient binary format that resembles a compact JSON.</li>
<li><a href="https://github.com/alexcrichton/toml-rs">TOML</a>, a minimal configuration format used by <a href="http://doc.crates.io/manifest.html">Cargo</a>.</li>
<li><a href="https://github.com/birkenfeld/serde-pickle">Pickle</a>, a format common in the Python world.</li>
<li><a href="https://github.com/ron-rs/ron">RON</a>, a Rusty Object Notation.</li>
<li><a href="https://github.com/zonyitoo/bson-rs">BSON</a>, the data storage and network transfer format used by MongoDB.</li>
<li><a href="https://github.com/flavray/avro-rs">Avro</a>, a binary format used within Apache Hadoop, with support for schema
definition.</li>
<li><a href="https://github.com/callum-oakley/json5-rs">JSON5</a>, a superset of JSON including some productions from ES5.</li>
<li><a href="https://github.com/jamesmunns/postcard">Postcard</a>, a no_std and embedded-systems friendly compact binary format.</li>
<li><a href="https://docs.rs/serde_qs">URL</a> query strings, in the x-www-form-urlencoded format.</li>
<li><a href="https://github.com/softprops/envy">Envy</a>, a way to deserialize environment variables into Rust structs.
<em>(deserialization only)</em></li>
<li><a href="https://github.com/softprops/envy-store">Envy Store</a>, a way to deserialize <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html">AWS Parameter Store</a> parameters into
Rust structs. <em>(deserialization only)</em></li>
<li><a href="https://github.com/rotty/lexpr-rs">S-expressions</a>, the textual representation of code and data used by the
Lisp language family.</li>
<li><a href="https://docs.rs/zvariant">D-Bus</a>s binary wire format.</li>
<li><a href="https://github.com/google/flatbuffers/tree/master/rust/flexbuffers">FlexBuffers</a>, the schemaless cousin of Googles FlatBuffers zero-copy serialization format.</li>
<li><a href="https://docs.rs/serde_dynamo">DynamoDB Items</a>, the format used by <a href="https://docs.rs/rusoto_dynamodb">rusoto_dynamodb</a> to transfer data to
and from DynamoDB.</li>
</ul>
</div><h2 id="modules" class="section-header"><a href="#modules">Modules</a></h2>
<table><tr class="module-item"><td><a class="mod" href="de/index.html" title="serde::de mod">de</a></td><td class="docblock-short"><p>Generic data structure deserialization framework.</p>
</td></tr><tr class="module-item"><td><a class="mod" href="ser/index.html" title="serde::ser mod">ser</a></td><td class="docblock-short"><p>Generic data structure serialization framework.</p>
</td></tr></table><h2 id="macros" class="section-header"><a href="#macros">Macros</a></h2>
<table><tr class="module-item"><td><a class="macro" href="macro.forward_to_deserialize_any.html" title="serde::forward_to_deserialize_any macro">forward_to_deserialize_any</a></td><td class="docblock-short"><p>Helper macro when implementing the <code>Deserializer</code> part of a new data format
for Serde.</p>
</td></tr><tr class="module-item"><td><a class="macro" href="macro.serde_if_integer128.html" title="serde::serde_if_integer128 macro">serde_if_integer128</a></td><td class="docblock-short"><p>Conditional compilation depending on whether Serde is built with support for
128-bit integers.</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.Deserialize.html" title="serde::Deserialize trait">Deserialize</a></td><td class="docblock-short"><p>A <strong>data structure</strong> that can be deserialized from any data format supported
by Serde.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.Deserializer.html" title="serde::Deserializer trait">Deserializer</a></td><td class="docblock-short"><p>A <strong>data format</strong> that can deserialize any data structure supported by
Serde.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.Serialize.html" title="serde::Serialize trait">Serialize</a></td><td class="docblock-short"><p>A <strong>data structure</strong> that can be serialized into any data format supported
by Serde.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.Serializer.html" title="serde::Serializer trait">Serializer</a></td><td class="docblock-short"><p>A <strong>data format</strong> that can serialize any data structure supported by Serde.</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="serde"></div>
<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.forward_to_deserialize_any.html">
</head>
<body>
<p>Redirecting to <a href="macro.forward_to_deserialize_any.html">macro.forward_to_deserialize_any.html</a>...</p>
<script>location.replace("macro.forward_to_deserialize_any.html" + location.search + location.hash);</script>
</body>
</html>
@@ -0,0 +1,57 @@
<!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="Helper macro when implementing the `Deserializer` part of a new data format for Serde."><meta name="keywords" content="rust, rustlang, rust-lang, forward_to_deserialize_any"><title>serde::forward_to_deserialize_any - 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">&#9776;</div><a href='../serde/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">serde</a></p><div id="sidebar-vars" data-name="forward_to_deserialize_any" 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" 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="in-band">Macro <a href="index.html">serde</a>::<wbr><a class="macro" href="">forward_to_deserialize_any</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../src/serde/macros.rs.html#112-120" title="goto source code">[src]</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">forward_to_deserialize_any</span> {
(<span class="op">&lt;</span><span class="macro-nonterminal">$</span><span class="macro-nonterminal">visitor</span>:<span class="ident">ident</span>: <span class="ident">Visitor</span><span class="op">&lt;</span><span class="macro-nonterminal">$</span><span class="macro-nonterminal">lifetime</span>:<span class="ident">tt</span><span class="op">&gt;</span><span class="op">&gt;</span> $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">func</span>:<span class="ident">ident</span>)<span class="kw-2">*</span>) <span class="op">=</span><span class="op">&gt;</span> { ... };
($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">func</span>:<span class="ident">ident</span>)<span class="kw-2">*</span>) <span class="op">=</span><span class="op">&gt;</span> { ... };
}</pre></div>
</div><div class="docblock"><p>Helper macro when implementing the <code>Deserializer</code> part of a new data format
for Serde.</p>
<p>Some <a href="trait.Deserializer.html"><code>Deserializer</code></a> implementations for self-describing formats do not
care what hint the <a href="de/trait.Visitor.html"><code>Visitor</code></a> gives them, they just want to blindly call
the <a href="de/trait.Visitor.html"><code>Visitor</code></a> method corresponding to the data they can tell is in the
input. This requires repetitive implementations of all the <a href="trait.Deserializer.html"><code>Deserializer</code></a>
trait methods.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="attribute">#[<span class="ident">inline</span>]</span>
<span class="kw">fn</span> <span class="ident">deserialize_bool</span><span class="op">&lt;</span><span class="ident">V</span><span class="op">&gt;</span>(<span class="self">self</span>, <span class="ident">visitor</span>: <span class="ident">V</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">V</span>::<span class="ident">Value</span>, <span class="self">Self</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">V</span>: <span class="ident">Visitor</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="self">self</span>.<span class="ident">deserialize_any</span>(<span class="ident">visitor</span>)
}</pre></div>
<p>The <code>forward_to_deserialize_any!</code> macro implements these simple forwarding
methods so that they forward directly to <a href="trait.Deserializer.html#tymethod.deserialize_any"><code>Deserializer::deserialize_any</code></a>.
You can choose which methods to forward.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">impl</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span> <span class="ident">Deserializer</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span> <span class="kw">for</span> <span class="ident">MyDeserializer</span> {
<span class="kw">fn</span> <span class="ident">deserialize_any</span><span class="op">&lt;</span><span class="ident">V</span><span class="op">&gt;</span>(<span class="self">self</span>, <span class="ident">visitor</span>: <span class="ident">V</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">V</span>::<span class="ident">Value</span>, <span class="self">Self</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">V</span>: <span class="ident">Visitor</span><span class="op">&lt;</span><span class="lifetime">&#39;de</span><span class="op">&gt;</span>,
{
<span class="comment">/* ... */</span>
}
<span class="macro">forward_to_deserialize_any</span><span class="macro">!</span> {
<span class="ident">bool</span> <span class="ident">i8</span> <span class="ident">i16</span> <span class="ident">i32</span> <span class="ident">i64</span> <span class="ident">i128</span> <span class="ident">u8</span> <span class="ident">u16</span> <span class="ident">u32</span> <span class="ident">u64</span> <span class="ident">u128</span> <span class="ident">f32</span> <span class="ident">f64</span> <span class="ident">char</span> <span class="ident">str</span> <span class="ident">string</span>
<span class="ident">bytes</span> <span class="ident">byte_buf</span> <span class="ident">option</span> <span class="ident">unit</span> <span class="ident">unit_struct</span> <span class="ident">newtype_struct</span> <span class="ident">seq</span> <span class="ident">tuple</span>
<span class="ident">tuple_struct</span> <span class="ident">map</span> <span class="kw">struct</span> <span class="kw">enum</span> <span class="ident">identifier</span> <span class="ident">ignored_any</span>
}
}</pre></div>
<p>The macro assumes the convention that your <code>Deserializer</code> lifetime parameter
is called <code>'de</code> and that the <code>Visitor</code> type parameters on each method are
called <code>V</code>. A different type parameter and a different lifetime can be
specified explicitly if necessary.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="macro">forward_to_deserialize_any</span><span class="macro">!</span> {
<span class="op">&lt;</span><span class="ident">W</span>: <span class="ident">Visitor</span><span class="op">&lt;</span><span class="lifetime">&#39;q</span><span class="op">&gt;</span><span class="op">&gt;</span>
<span class="ident">bool</span> <span class="ident">i8</span> <span class="ident">i16</span> <span class="ident">i32</span> <span class="ident">i64</span> <span class="ident">i128</span> <span class="ident">u8</span> <span class="ident">u16</span> <span class="ident">u32</span> <span class="ident">u64</span> <span class="ident">u128</span> <span class="ident">f32</span> <span class="ident">f64</span> <span class="ident">char</span> <span class="ident">str</span> <span class="ident">string</span>
<span class="ident">bytes</span> <span class="ident">byte_buf</span> <span class="ident">option</span> <span class="ident">unit</span> <span class="ident">unit_struct</span> <span class="ident">newtype_struct</span> <span class="ident">seq</span> <span class="ident">tuple</span>
<span class="ident">tuple_struct</span> <span class="ident">map</span> <span class="kw">struct</span> <span class="kw">enum</span> <span class="ident">identifier</span> <span class="ident">ignored_any</span>
}</pre></div>
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="serde"></div>
<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.serde_if_integer128.html">
</head>
<body>
<p>Redirecting to <a href="macro.serde_if_integer128.html">macro.serde_if_integer128.html</a>...</p>
<script>location.replace("macro.serde_if_integer128.html" + location.search + location.hash);</script>
</body>
</html>
+57
View File
@@ -0,0 +1,57 @@
<!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="Conditional compilation depending on whether Serde is built with support for 128-bit integers."><meta name="keywords" content="rust, rustlang, rust-lang, serde_if_integer128"><title>serde::serde_if_integer128 - 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">&#9776;</div><a href='../serde/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">serde</a></p><div id="sidebar-vars" data-name="serde_if_integer128" 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" 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="in-band">Macro <a href="index.html">serde</a>::<wbr><a class="macro" href="">serde_if_integer128</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../src/serde/integer128.rs.html#71-75" title="goto source code">[src]</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">serde_if_integer128</span> {
($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tt</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>) <span class="op">=</span><span class="op">&gt;</span> { ... };
}</pre></div>
</div><div class="docblock"><p>Conditional compilation depending on whether Serde is built with support for
128-bit integers.</p>
<p>Data formats that wish to support Rust compiler versions older than 1.26
(or targets that lack 128-bit integers) may place the i128 / u128 methods
of their Serializer and Deserializer behind this macro.</p>
<p>Data formats that require a minimum Rust compiler version of at least 1.26,
or do not target platforms that lack 128-bit integers, do not need to
bother with this macro and may assume support for 128-bit integers.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::{<span class="ident">serde_if_integer128</span>, <span class="ident">Serializer</span>};
<span class="kw">impl</span> <span class="ident">Serializer</span> <span class="kw">for</span> <span class="ident">MySerializer</span> {
<span class="kw">type</span> <span class="prelude-val">Ok</span> <span class="op">=</span> ();
<span class="kw">type</span> <span class="ident">Error</span> <span class="op">=</span> <span class="ident">Error</span>;
<span class="kw">fn</span> <span class="ident">serialize_i64</span>(<span class="self">self</span>, <span class="ident">v</span>: <span class="ident">i64</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span>::<span class="prelude-val">Ok</span>, <span class="self">Self</span>::<span class="ident">Error</span><span class="op">&gt;</span> {
<span class="comment">/* ... */</span>
}
<span class="comment">/* ... */</span>
<span class="macro">serde_if_integer128</span><span class="macro">!</span> {
<span class="kw">fn</span> <span class="ident">serialize_i128</span>(<span class="self">self</span>, <span class="ident">v</span>: <span class="ident">i128</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span>::<span class="prelude-val">Ok</span>, <span class="self">Self</span>::<span class="ident">Error</span><span class="op">&gt;</span> {
<span class="comment">/* ... */</span>
}
<span class="kw">fn</span> <span class="ident">serialize_u128</span>(<span class="self">self</span>, <span class="ident">v</span>: <span class="ident">u128</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span>::<span class="prelude-val">Ok</span>, <span class="self">Self</span>::<span class="ident">Error</span><span class="op">&gt;</span> {
<span class="comment">/* ... */</span>
}
}
}</pre></div>
<p>When Serde is built with support for 128-bit integers, this macro expands
transparently into just the input tokens.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="macro">macro_rules</span><span class="macro">!</span> <span class="ident">serde_if_integer128</span> {
($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tt</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>) <span class="op">=</span><span class="op">&gt;</span> {
$(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tt</span>)<span class="op">*</span>
};
}</pre></div>
<p>When built without support for 128-bit integers, this macro expands to
nothing.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="macro">macro_rules</span><span class="macro">!</span> <span class="ident">serde_if_integer128</span> {
($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">tt</span>:<span class="ident">tt</span>)<span class="kw-2">*</span>) <span class="op">=</span><span class="op">&gt;</span> {};
}</pre></div>
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="serde"></div>
<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=../../../serde/ser/struct.Impossible.html">
</head>
<body>
<p>Redirecting to <a href="../../../serde/ser/struct.Impossible.html">../../../serde/ser/struct.Impossible.html</a>...</p>
<script>location.replace("../../../serde/ser/struct.Impossible.html" + location.search + location.hash);</script>
</body>
</html>
+135
View File
@@ -0,0 +1,135 @@
<!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="Generic data structure serialization framework."><meta name="keywords" content="rust, rustlang, rust-lang, ser"><title>serde::ser - 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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Module ser</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#reexports">Re-exports</a></li><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li></ul></div><p class="location"><a href="../index.html">serde</a></p><div id="sidebar-vars" data-name="ser" data-ty="mod" 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" 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="in-band">Module <a href="../index.html">serde</a>::<wbr><a class="mod" href="">ser</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/ser/mod.rs.html#1-1964" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Generic data structure serialization framework.</p>
<p>The two most important traits in this module are <a href="../trait.Serialize.html"><code>Serialize</code></a> and
<a href="../trait.Serializer.html"><code>Serializer</code></a>.</p>
<ul>
<li><strong>A type that implements <code>Serialize</code> is a data structure</strong> that can be
serialized to any data format supported by Serde, and conversely</li>
<li><strong>A type that implements <code>Serializer</code> is a data format</strong> that can
serialize any data structure supported by Serde.</li>
</ul>
<h1 id="the-serialize-trait" class="section-header"><a href="#the-serialize-trait">The Serialize trait</a></h1>
<p>Serde provides <a href="../trait.Serialize.html"><code>Serialize</code></a> implementations for many Rust primitive and
standard library types. The complete list is below. All of these can be
serialized using Serde out of the box.</p>
<p>Additionally, Serde provides a procedural macro called <a href="https://crates.io/crates/serde_derive"><code>serde_derive</code></a> to
automatically generate <a href="../trait.Serialize.html"><code>Serialize</code></a> implementations for structs and enums
in your program. See the <a href="https://serde.rs/derive.html">derive section of the manual</a> for how to use this.</p>
<p>In rare cases it may be necessary to implement <a href="../trait.Serialize.html"><code>Serialize</code></a> manually for
some type in your program. See the <a href="https://serde.rs/impl-serialize.html">Implementing <code>Serialize</code></a> section of the
manual for more about this.</p>
<p>Third-party crates may provide <a href="../trait.Serialize.html"><code>Serialize</code></a> implementations for types that
they expose. For example the <a href="https://crates.io/crates/linked-hash-map"><code>linked-hash-map</code></a> crate provides a
<a href="https://docs.rs/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap.html"><code>LinkedHashMap&lt;K, V&gt;</code></a> type that is serializable by Serde because the crate
provides an implementation of <a href="../trait.Serialize.html"><code>Serialize</code></a> for it.</p>
<h1 id="the-serializer-trait" class="section-header"><a href="#the-serializer-trait">The Serializer trait</a></h1>
<p><a href="../trait.Serializer.html"><code>Serializer</code></a> implementations are provided by third-party crates, for
example <a href="https://github.com/serde-rs/json"><code>serde_json</code></a>, <a href="https://github.com/dtolnay/serde-yaml"><code>serde_yaml</code></a> and <a href="https://github.com/servo/bincode"><code>bincode</code></a>.</p>
<p>A partial list of well-maintained formats is given on the <a href="https://serde.rs/#data-formats">Serde
website</a>.</p>
<h1 id="implementations-of-serialize-provided-by-serde" class="section-header"><a href="#implementations-of-serialize-provided-by-serde">Implementations of Serialize provided by Serde</a></h1>
<ul>
<li><strong>Primitive types</strong>:
<ul>
<li>bool</li>
<li>i8, i16, i32, i64, i128, isize</li>
<li>u8, u16, u32, u64, u128, usize</li>
<li>f32, f64</li>
<li>char</li>
<li>str</li>
<li>&amp;T and &amp;mut T</li>
</ul>
</li>
<li><strong>Compound types</strong>:
<ul>
<li>[T]</li>
<li>[T; 0] through [T; 32]</li>
<li>tuples up to size 16</li>
</ul>
</li>
<li><strong>Common standard library types</strong>:
<ul>
<li>String</li>
<li>Option&lt;T&gt;</li>
<li>Result&lt;T, E&gt;</li>
<li>PhantomData&lt;T&gt;</li>
</ul>
</li>
<li><strong>Wrapper types</strong>:
<ul>
<li>Box&lt;T&gt;</li>
<li>Cow&lt;a, T&gt;</li>
<li>Cell&lt;T&gt;</li>
<li>RefCell&lt;T&gt;</li>
<li>Mutex&lt;T&gt;</li>
<li>RwLock&lt;T&gt;</li>
<li>Rc&lt;T&gt;<em>(if</em> features = [“rc”] <em>is enabled)</em></li>
<li>Arc&lt;T&gt;<em>(if</em> features = [“rc”] <em>is enabled)</em></li>
</ul>
</li>
<li><strong>Collection types</strong>:
<ul>
<li>BTreeMap&lt;K, V&gt;</li>
<li>BTreeSet&lt;T&gt;</li>
<li>BinaryHeap&lt;T&gt;</li>
<li>HashMap&lt;K, V, H&gt;</li>
<li>HashSet&lt;T, H&gt;</li>
<li>LinkedList&lt;T&gt;</li>
<li>VecDeque&lt;T&gt;</li>
<li>Vec&lt;T&gt;</li>
</ul>
</li>
<li><strong>FFI types</strong>:
<ul>
<li>CStr</li>
<li>CString</li>
<li>OsStr</li>
<li>OsString</li>
</ul>
</li>
<li><strong>Miscellaneous standard library types</strong>:
<ul>
<li>Duration</li>
<li>SystemTime</li>
<li>Path</li>
<li>PathBuf</li>
<li>Range&lt;T&gt;</li>
<li>RangeInclusive&lt;T&gt;</li>
<li>Bound&lt;T&gt;</li>
<li>num::NonZero*</li>
<li><code>!</code> <em>(unstable)</em></li>
</ul>
</li>
<li><strong>Net types</strong>:
<ul>
<li>IpAddr</li>
<li>Ipv4Addr</li>
<li>Ipv6Addr</li>
<li>SocketAddr</li>
<li>SocketAddrV4</li>
<li>SocketAddrV6</li>
</ul>
</li>
</ul>
</div><h2 id="reexports" class="section-header"><a href="#reexports">Re-exports</a></h2>
<table><tr><td><code>pub use std::error::<a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">Error</a> as StdError;</code></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.Impossible.html" title="serde::ser::Impossible struct">Impossible</a></td><td class="docblock-short"><p>Helper type for implementing a <code>Serializer</code> that does not support
serializing one of the compound types.</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.Error.html" title="serde::ser::Error trait">Error</a></td><td class="docblock-short"><p>Trait used by <code>Serialize</code> implementations to generically construct
errors belonging to the <code>Serializer</code> against which they are
currently running.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.Serialize.html" title="serde::ser::Serialize trait">Serialize</a></td><td class="docblock-short"><p>A <strong>data structure</strong> that can be serialized into any data format supported
by Serde.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.SerializeMap.html" title="serde::ser::SerializeMap trait">SerializeMap</a></td><td class="docblock-short"><p>Returned from <code>Serializer::serialize_map</code>.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.SerializeSeq.html" title="serde::ser::SerializeSeq trait">SerializeSeq</a></td><td class="docblock-short"><p>Returned from <code>Serializer::serialize_seq</code>.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.SerializeStruct.html" title="serde::ser::SerializeStruct trait">SerializeStruct</a></td><td class="docblock-short"><p>Returned from <code>Serializer::serialize_struct</code>.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.SerializeStructVariant.html" title="serde::ser::SerializeStructVariant trait">SerializeStructVariant</a></td><td class="docblock-short"><p>Returned from <code>Serializer::serialize_struct_variant</code>.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.SerializeTuple.html" title="serde::ser::SerializeTuple trait">SerializeTuple</a></td><td class="docblock-short"><p>Returned from <code>Serializer::serialize_tuple</code>.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.SerializeTupleStruct.html" title="serde::ser::SerializeTupleStruct trait">SerializeTupleStruct</a></td><td class="docblock-short"><p>Returned from <code>Serializer::serialize_tuple_struct</code>.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.SerializeTupleVariant.html" title="serde::ser::SerializeTupleVariant trait">SerializeTupleVariant</a></td><td class="docblock-short"><p>Returned from <code>Serializer::serialize_tuple_variant</code>.</p>
</td></tr><tr class="module-item"><td><a class="trait" href="trait.Serializer.html" title="serde::ser::Serializer trait">Serializer</a></td><td class="docblock-short"><p>A <strong>data format</strong> that can serialize any data structure supported by Serde.</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
+1
View File
@@ -0,0 +1 @@
initSidebarItems({"struct":[["Impossible","Helper type for implementing a `Serializer` that does not support serializing one of the compound types."]],"trait":[["Error","Trait used by `Serialize` implementations to generically construct errors belonging to the `Serializer` against which they are currently running."],["Serialize","A data structure that can be serialized into any data format supported by Serde."],["SerializeMap","Returned from `Serializer::serialize_map`."],["SerializeSeq","Returned from `Serializer::serialize_seq`."],["SerializeStruct","Returned from `Serializer::serialize_struct`."],["SerializeStructVariant","Returned from `Serializer::serialize_struct_variant`."],["SerializeTuple","Returned from `Serializer::serialize_tuple`."],["SerializeTupleStruct","Returned from `Serializer::serialize_tuple_struct`."],["SerializeTupleVariant","Returned from `Serializer::serialize_tuple_variant`."],["Serializer","A data format that can serialize any data structure supported by Serde."]]});
File diff suppressed because one or more lines are too long
+34
View File
@@ -0,0 +1,34 @@
<!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="Trait used by `Serialize` implementations to generically construct errors belonging to the `Serializer` against which they are currently running."><meta name="keywords" content="rust, rustlang, rust-lang, Error"><title>serde::ser::Error - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait Error</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.custom">custom</a></div><a class="sidebar-title" href="#foreign-impls">Implementations on Foreign Types</a><div class="sidebar-links"><a href="#impl-Error-for-Error">Error</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a></p><div id="sidebar-vars" data-name="Error" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a>::<wbr><a class="trait" href="">Error</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/ser/mod.rs.html#183" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait Error: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">StdError</a> {
fn <a href="#tymethod.custom" class="fnname">custom</a>&lt;T&gt;(msg: T) -&gt; Self<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a></span>;
}</pre></div><div class="docblock"><p>Trait used by <code>Serialize</code> implementations to generically construct
errors belonging to the <code>Serializer</code> against which they are
currently running.</p>
<h1 id="example-implementation" class="section-header"><a href="#example-implementation">Example implementation</a></h1>
<p>The <a href="https://serde.rs/data-format.html">example data format</a> presented on the website shows an error
type appropriate for a basic JSON data format.</p>
</div><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.custom" class="method"><code>fn <a href="#tymethod.custom" class="fnname">custom</a>&lt;T&gt;(msg: T) -&gt; Self <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#183" title="goto source code">[src]</a></h3><div class="docblock"><p>Used when a <a href="../trait.Serialize.html"><code>Serialize</code></a> implementation encounters any error
while serializing a type.</p>
<p>The message should not be capitalized and should not end with a
period.</p>
<p>For example, a filesystem <a href="https://doc.rust-lang.org/std/path/struct.Path.html"><code>Path</code></a> may refuse to serialize
itself if it contains invalid UTF-8 data.</p>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">ser</span>::{<span class="self">self</span>, <span class="ident">Serialize</span>, <span class="ident">Serializer</span>};
<span class="kw">impl</span> <span class="ident">Serialize</span> <span class="kw">for</span> <span class="ident">Path</span> {
<span class="kw">fn</span> <span class="ident">serialize</span><span class="op">&lt;</span><span class="ident">S</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">serializer</span>: <span class="ident">S</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">S</span>::<span class="prelude-val">Ok</span>, <span class="ident">S</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">S</span>: <span class="ident">Serializer</span>,
{
<span class="kw">match</span> <span class="self">self</span>.<span class="ident">to_str</span>() {
<span class="prelude-val">Some</span>(<span class="ident">s</span>) <span class="op">=</span><span class="op">&gt;</span> <span class="ident">serializer</span>.<span class="ident">serialize_str</span>(<span class="ident">s</span>),
<span class="prelude-val">None</span> <span class="op">=</span><span class="op">&gt;</span> <span class="prelude-val">Err</span>(<span class="ident">ser</span>::<span class="ident">Error</span>::<span class="ident">custom</span>(<span class="string">&quot;path contains invalid UTF-8 characters&quot;</span>)),
}
}
}</pre></div>
</div></div><span class="loading-content">Loading content...</span><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><h3 id="impl-Error-for-Error" class="impl"><code class="in-band">impl <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a> for <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Error.html" title="struct core::fmt::Error">Error</a></code><a href="#impl-Error-for-Error" class="anchor"></a><a class="srclink" href="../../src/serde/ser/fmt.rs.html#4-8" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.custom" class="method hidden"><code>fn <a href="#method.custom" class="fnname">custom</a>&lt;T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>&gt;(_msg: T) -&gt; Self</code><a class="srclink" href="../../src/serde/ser/fmt.rs.html#5-7" title="goto source code">[src]</a></h4></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-Error" class="impl"><code class="in-band">impl <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a> for serde::de::value::<a class="struct" href="../../serde/de/value/struct.Error.html" title="struct serde::de::value::Error">Error</a></code><a href="#impl-Error" class="anchor"></a><a class="srclink" href="../../src/serde/de/value.rs.html#84-92" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.custom-1" class="method hidden"><code>fn <a href="#method.custom-1" class="fnname">custom</a>&lt;T&gt;(msg: T) -&gt; Self <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/de/value.rs.html#86-91" title="goto source code">[src]</a></h4></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/ser/trait.Error.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<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
+61
View File
@@ -0,0 +1,61 @@
<!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="Returned from `Serializer::serialize_map`."><meta name="keywords" content="rust, rustlang, rust-lang, SerializeMap"><title>serde::ser::SerializeMap - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait SerializeMap</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Error">Error</a><a href="#associatedtype.Ok">Ok</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.end">end</a><a href="#tymethod.serialize_key">serialize_key</a><a href="#tymethod.serialize_value">serialize_value</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.serialize_entry">serialize_entry</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a></p><div id="sidebar-vars" data-name="SerializeMap" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a>::<wbr><a class="trait" href="">SerializeMap</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/ser/mod.rs.html#1769-1828" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait SerializeMap {
type <a href="#associatedtype.Ok" class="type">Ok</a>;
type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>;
fn <a href="#tymethod.serialize_key" class="fnname">serialize_key</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, key: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeMap.html#associatedtype.Error" title="type serde::ser::SerializeMap::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a></span>;
<div class="item-spacer"></div> fn <a href="#tymethod.serialize_value" class="fnname">serialize_value</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeMap.html#associatedtype.Error" title="type serde::ser::SerializeMap::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a></span>;
<div class="item-spacer"></div> fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeMap.html#associatedtype.Ok" title="type serde::ser::SerializeMap::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeMap.html#associatedtype.Error" title="type serde::ser::SerializeMap::Error">Error</a>&gt;;
fn <a href="#method.serialize_entry" class="fnname">serialize_entry</a>&lt;K:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, V:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>K, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>V<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeMap.html#associatedtype.Error" title="type serde::ser::SerializeMap::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a></span>,
{ ... }
}</pre></div><div class="docblock"><p>Returned from <code>Serializer::serialize_map</code>.</p>
<h1 id="example-use" class="section-header"><a href="#example-use">Example use</a></h1>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">ser</span>::{<span class="ident">Serialize</span>, <span class="ident">Serializer</span>, <span class="ident">SerializeMap</span>};
<span class="kw">impl</span><span class="op">&lt;</span><span class="ident">K</span>, <span class="ident">V</span><span class="op">&gt;</span> <span class="ident">Serialize</span> <span class="kw">for</span> <span class="ident">HashMap</span><span class="op">&lt;</span><span class="ident">K</span>, <span class="ident">V</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">K</span>: <span class="ident">Serialize</span>,
<span class="ident">V</span>: <span class="ident">Serialize</span>,
{
<span class="kw">fn</span> <span class="ident">serialize</span><span class="op">&lt;</span><span class="ident">S</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">serializer</span>: <span class="ident">S</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">S</span>::<span class="prelude-val">Ok</span>, <span class="ident">S</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">S</span>: <span class="ident">Serializer</span>,
{
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">serializer</span>.<span class="ident">serialize_map</span>(<span class="prelude-val">Some</span>(<span class="self">self</span>.<span class="ident">len</span>()))<span class="question-mark">?</span>;
<span class="kw">for</span> (<span class="ident">k</span>, <span class="ident">v</span>) <span class="kw">in</span> <span class="self">self</span> {
<span class="ident">map</span>.<span class="ident">serialize_entry</span>(<span class="ident">k</span>, <span class="ident">v</span>)<span class="question-mark">?</span>;
}
<span class="ident">map</span>.<span class="ident">end</span>()
}
}</pre></div>
<h1 id="example-implementation" class="section-header"><a href="#example-implementation">Example implementation</a></h1>
<p>The <a href="https://serde.rs/data-format.html">example data format</a> presented on the website demonstrates an
implementation of <code>SerializeMap</code> for a basic JSON data format.</p>
</div><h2 id="associated-types" class="small-section-header">Associated Types<a href="#associated-types" class="anchor"></a></h2><div class="methods"><h3 id="associatedtype.Ok" class="method"><code>type <a href="#associatedtype.Ok" class="type">Ok</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1771" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Ok</code> type of our <code>Serializer</code>.</p>
</div><h3 id="associatedtype.Error" class="method"><code>type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1774" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Error</code> type of our <code>Serializer</code>.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.serialize_key" class="method"><code>fn <a href="#tymethod.serialize_key" class="fnname">serialize_key</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, key: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeMap.html#associatedtype.Error" title="type serde::ser::SerializeMap::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1782-1784" title="goto source code">[src]</a></h3><div class="docblock"><p>Serialize a map key.</p>
<p>If possible, <code>Serialize</code> implementations are encouraged to use
<code>serialize_entry</code> instead as it may be implemented more efficiently in
some formats compared to a pair of calls to <code>serialize_key</code> and
<code>serialize_value</code>.</p>
</div><h3 id="tymethod.serialize_value" class="method"><code>fn <a href="#tymethod.serialize_value" class="fnname">serialize_value</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeMap.html#associatedtype.Error" title="type serde::ser::SerializeMap::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1792-1794" title="goto source code">[src]</a></h3><div class="docblock"><p>Serialize a map value.</p>
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
<p>Calling <code>serialize_value</code> before <code>serialize_key</code> is incorrect and is
allowed to panic or produce bogus results.</p>
</div><h3 id="tymethod.end" class="method"><code>fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeMap.html#associatedtype.Ok" title="type serde::ser::SerializeMap::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeMap.html#associatedtype.Error" title="type serde::ser::SerializeMap::Error">Error</a>&gt;</code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1827" title="goto source code">[src]</a></h3><div class="docblock"><p>Finish serializing a map.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="provided-methods" class="small-section-header">Provided methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><h3 id="method.serialize_entry" class="method"><code>fn <a href="#method.serialize_entry" class="fnname">serialize_entry</a>&lt;K:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, V:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;key: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>K, <br>&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>V<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeMap.html#associatedtype.Error" title="type serde::ser::SerializeMap::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1813-1824" title="goto source code">[src]</a></h3><div class="docblock"><p>Serialize a map entry consisting of a key and a value.</p>
<p>Some <a href="../trait.Serialize.html"><code>Serialize</code></a> types are not able to hold a key and value in memory
at the same time so <code>SerializeMap</code> implementations are required to
support <a href="#tymethod.serialize_key"><code>serialize_key</code></a> and <a href="#tymethod.serialize_value"><code>serialize_value</code></a> individually. The
<code>serialize_entry</code> method allows serializers to optimize for the case
where key and value are both available. <a href="../trait.Serialize.html"><code>Serialize</code></a> implementations
are encouraged to use <code>serialize_entry</code> if possible.</p>
<p>The default implementation delegates to <a href="#tymethod.serialize_key"><code>serialize_key</code></a> and
<a href="#tymethod.serialize_value"><code>serialize_value</code></a>. This is appropriate for serializers that do not
care about performance or are not able to optimize <code>serialize_entry</code> any
better than this.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-SerializeMap" class="impl"><code class="in-band">impl&lt;Ok, Error&gt; <a class="trait" href="../../serde/ser/trait.SerializeMap.html" title="trait serde::ser::SerializeMap">SerializeMap</a> for <a class="struct" href="../../serde/ser/struct.Impossible.html" title="struct serde::ser::Impossible">Impossible</a>&lt;Ok, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Error: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>,&nbsp;</span></code><a href="#impl-SerializeMap" class="anchor"></a><a class="srclink" href="../../src/serde/ser/impossible.rs.html#148-174" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Ok-1" class="type"><code>type <a href="#associatedtype.Ok-1" class="type">Ok</a> = Ok</code></h4><h4 id="associatedtype.Error-1" class="type"><code>type <a href="#associatedtype.Error-1" class="type">Error</a> = Error</code></h4><h4 id="method.serialize_key" class="method hidden"><code>fn <a href="#method.serialize_key" class="fnname">serialize_key</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, key: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#155-161" title="goto source code">[src]</a></h4><h4 id="method.serialize_value" class="method hidden"><code>fn <a href="#method.serialize_value" class="fnname">serialize_value</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#163-169" title="goto source code">[src]</a></h4><h4 id="method.end" class="method hidden"><code>fn <a href="#method.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Ok, Error&gt;</code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#171-173" title="goto source code">[src]</a></h4></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/ser/trait.SerializeMap.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
+37
View File
@@ -0,0 +1,37 @@
<!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="Returned from `Serializer::serialize_seq`."><meta name="keywords" content="rust, rustlang, rust-lang, SerializeSeq"><title>serde::ser::SerializeSeq - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait SerializeSeq</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Error">Error</a><a href="#associatedtype.Ok">Ok</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.end">end</a><a href="#tymethod.serialize_element">serialize_element</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a></p><div id="sidebar-vars" data-name="SerializeSeq" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a>::<wbr><a class="trait" href="">SerializeSeq</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/ser/mod.rs.html#1500-1514" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait SerializeSeq {
type <a href="#associatedtype.Ok" class="type">Ok</a>;
type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>;
fn <a href="#tymethod.serialize_element" class="fnname">serialize_element</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeSeq.html#associatedtype.Error" title="type serde::ser::SerializeSeq::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a></span>;
<div class="item-spacer"></div> fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeSeq.html#associatedtype.Ok" title="type serde::ser::SerializeSeq::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeSeq.html#associatedtype.Error" title="type serde::ser::SerializeSeq::Error">Error</a>&gt;;
}</pre></div><div class="docblock"><p>Returned from <code>Serializer::serialize_seq</code>.</p>
<h1 id="example-use" class="section-header"><a href="#example-use">Example use</a></h1>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">ser</span>::{<span class="ident">Serialize</span>, <span class="ident">Serializer</span>, <span class="ident">SerializeSeq</span>};
<span class="kw">impl</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span> <span class="ident">Serialize</span> <span class="kw">for</span> <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">T</span>: <span class="ident">Serialize</span>,
{
<span class="kw">fn</span> <span class="ident">serialize</span><span class="op">&lt;</span><span class="ident">S</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">serializer</span>: <span class="ident">S</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">S</span>::<span class="prelude-val">Ok</span>, <span class="ident">S</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">S</span>: <span class="ident">Serializer</span>,
{
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">seq</span> <span class="op">=</span> <span class="ident">serializer</span>.<span class="ident">serialize_seq</span>(<span class="prelude-val">Some</span>(<span class="self">self</span>.<span class="ident">len</span>()))<span class="question-mark">?</span>;
<span class="kw">for</span> <span class="ident">element</span> <span class="kw">in</span> <span class="self">self</span> {
<span class="ident">seq</span>.<span class="ident">serialize_element</span>(<span class="ident">element</span>)<span class="question-mark">?</span>;
}
<span class="ident">seq</span>.<span class="ident">end</span>()
}
}</pre></div>
<h1 id="example-implementation" class="section-header"><a href="#example-implementation">Example implementation</a></h1>
<p>The <a href="https://serde.rs/data-format.html">example data format</a> presented on the website demonstrates an
implementation of <code>SerializeSeq</code> for a basic JSON data format.</p>
</div><h2 id="associated-types" class="small-section-header">Associated Types<a href="#associated-types" class="anchor"></a></h2><div class="methods"><h3 id="associatedtype.Ok" class="method"><code>type <a href="#associatedtype.Ok" class="type">Ok</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1502" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Ok</code> type of our <code>Serializer</code>.</p>
</div><h3 id="associatedtype.Error" class="method"><code>type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1505" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Error</code> type of our <code>Serializer</code>.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.serialize_element" class="method"><code>fn <a href="#tymethod.serialize_element" class="fnname">serialize_element</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeSeq.html#associatedtype.Error" title="type serde::ser::SerializeSeq::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1508-1510" title="goto source code">[src]</a></h3><div class="docblock"><p>Serialize a sequence element.</p>
</div><h3 id="tymethod.end" class="method"><code>fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeSeq.html#associatedtype.Ok" title="type serde::ser::SerializeSeq::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeSeq.html#associatedtype.Error" title="type serde::ser::SerializeSeq::Error">Error</a>&gt;</code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1513" title="goto source code">[src]</a></h3><div class="docblock"><p>Finish serializing a sequence.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-SerializeSeq" class="impl"><code class="in-band">impl&lt;Ok, Error&gt; <a class="trait" href="../../serde/ser/trait.SerializeSeq.html" title="trait serde::ser::SerializeSeq">SerializeSeq</a> for <a class="struct" href="../../serde/ser/struct.Impossible.html" title="struct serde::ser::Impossible">Impossible</a>&lt;Ok, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Error: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>,&nbsp;</span></code><a href="#impl-SerializeSeq" class="anchor"></a><a class="srclink" href="../../src/serde/ser/impossible.rs.html#68-86" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Ok-1" class="type"><code>type <a href="#associatedtype.Ok-1" class="type">Ok</a> = Ok</code></h4><h4 id="associatedtype.Error-1" class="type"><code>type <a href="#associatedtype.Error-1" class="type">Error</a> = Error</code></h4><h4 id="method.serialize_element" class="method hidden"><code>fn <a href="#method.serialize_element" class="fnname">serialize_element</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#75-81" title="goto source code">[src]</a></h4><h4 id="method.end" class="method hidden"><code>fn <a href="#method.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Ok, Error&gt;</code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#83-85" title="goto source code">[src]</a></h4></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/ser/trait.SerializeSeq.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
+43
View File
@@ -0,0 +1,43 @@
<!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="Returned from `Serializer::serialize_struct`."><meta name="keywords" content="rust, rustlang, rust-lang, SerializeStruct"><title>serde::ser::SerializeStruct - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait SerializeStruct</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Error">Error</a><a href="#associatedtype.Ok">Ok</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.end">end</a><a href="#tymethod.serialize_field">serialize_field</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.skip_field">skip_field</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a></p><div id="sidebar-vars" data-name="SerializeStruct" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a>::<wbr><a class="trait" href="">SerializeStruct</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/ser/mod.rs.html#1863-1888" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait SerializeStruct {
type <a href="#associatedtype.Ok" class="type">Ok</a>;
type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>;
fn <a href="#tymethod.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStruct.html#associatedtype.Error" title="type serde::ser::SerializeStruct::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a></span>;
<div class="item-spacer"></div> fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeStruct.html#associatedtype.Ok" title="type serde::ser::SerializeStruct::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStruct.html#associatedtype.Error" title="type serde::ser::SerializeStruct::Error">Error</a>&gt;;
fn <a href="#method.skip_field" class="fnname">skip_field</a>(&amp;mut self, key: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStruct.html#associatedtype.Error" title="type serde::ser::SerializeStruct::Error">Error</a>&gt; { ... }
}</pre></div><div class="docblock"><p>Returned from <code>Serializer::serialize_struct</code>.</p>
<h1 id="example-use" class="section-header"><a href="#example-use">Example use</a></h1>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">ser</span>::{<span class="ident">Serialize</span>, <span class="ident">SerializeStruct</span>, <span class="ident">Serializer</span>};
<span class="kw">struct</span> <span class="ident">Rgb</span> {
<span class="ident">r</span>: <span class="ident">u8</span>,
<span class="ident">g</span>: <span class="ident">u8</span>,
<span class="ident">b</span>: <span class="ident">u8</span>,
}
<span class="kw">impl</span> <span class="ident">Serialize</span> <span class="kw">for</span> <span class="ident">Rgb</span> {
<span class="kw">fn</span> <span class="ident">serialize</span><span class="op">&lt;</span><span class="ident">S</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">serializer</span>: <span class="ident">S</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">S</span>::<span class="prelude-val">Ok</span>, <span class="ident">S</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">S</span>: <span class="ident">Serializer</span>,
{
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">rgb</span> <span class="op">=</span> <span class="ident">serializer</span>.<span class="ident">serialize_struct</span>(<span class="string">&quot;Rgb&quot;</span>, <span class="number">3</span>)<span class="question-mark">?</span>;
<span class="ident">rgb</span>.<span class="ident">serialize_field</span>(<span class="string">&quot;r&quot;</span>, <span class="kw-2">&amp;</span><span class="self">self</span>.<span class="ident">r</span>)<span class="question-mark">?</span>;
<span class="ident">rgb</span>.<span class="ident">serialize_field</span>(<span class="string">&quot;g&quot;</span>, <span class="kw-2">&amp;</span><span class="self">self</span>.<span class="ident">g</span>)<span class="question-mark">?</span>;
<span class="ident">rgb</span>.<span class="ident">serialize_field</span>(<span class="string">&quot;b&quot;</span>, <span class="kw-2">&amp;</span><span class="self">self</span>.<span class="ident">b</span>)<span class="question-mark">?</span>;
<span class="ident">rgb</span>.<span class="ident">end</span>()
}
}</pre></div>
<h1 id="example-implementation" class="section-header"><a href="#example-implementation">Example implementation</a></h1>
<p>The <a href="https://serde.rs/data-format.html">example data format</a> presented on the website demonstrates an
implementation of <code>SerializeStruct</code> for a basic JSON data format.</p>
</div><h2 id="associated-types" class="small-section-header">Associated Types<a href="#associated-types" class="anchor"></a></h2><div class="methods"><h3 id="associatedtype.Ok" class="method"><code>type <a href="#associatedtype.Ok" class="type">Ok</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1865" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Ok</code> type of our <code>Serializer</code>.</p>
</div><h3 id="associatedtype.Error" class="method"><code>type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1868" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Error</code> type of our <code>Serializer</code>.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.serialize_field" class="method"><code>fn <a href="#tymethod.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;key: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStruct.html#associatedtype.Error" title="type serde::ser::SerializeStruct::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1871-1877" title="goto source code">[src]</a></h3><div class="docblock"><p>Serialize a struct field.</p>
</div><h3 id="tymethod.end" class="method"><code>fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeStruct.html#associatedtype.Ok" title="type serde::ser::SerializeStruct::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStruct.html#associatedtype.Error" title="type serde::ser::SerializeStruct::Error">Error</a>&gt;</code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1887" title="goto source code">[src]</a></h3><div class="docblock"><p>Finish serializing a struct.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="provided-methods" class="small-section-header">Provided methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><h3 id="method.skip_field" class="method"><code>fn <a href="#method.skip_field" class="fnname">skip_field</a>(&amp;mut self, key: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStruct.html#associatedtype.Error" title="type serde::ser::SerializeStruct::Error">Error</a>&gt;</code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1881-1884" title="goto source code">[src]</a></h3><div class="docblock"><p>Indicate that a struct field has been skipped.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-SerializeStruct" class="impl"><code class="in-band">impl&lt;Ok, Error&gt; <a class="trait" href="../../serde/ser/trait.SerializeStruct.html" title="trait serde::ser::SerializeStruct">SerializeStruct</a> for <a class="struct" href="../../serde/ser/struct.Impossible.html" title="struct serde::ser::Impossible">Impossible</a>&lt;Ok, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Error: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>,&nbsp;</span></code><a href="#impl-SerializeStruct" class="anchor"></a><a class="srclink" href="../../src/serde/ser/impossible.rs.html#176-195" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Ok-1" class="type"><code>type <a href="#associatedtype.Ok-1" class="type">Ok</a> = Ok</code></h4><h4 id="associatedtype.Error-1" class="type"><code>type <a href="#associatedtype.Error-1" class="type">Error</a> = Error</code></h4><h4 id="method.serialize_field" class="method hidden"><code>fn <a href="#method.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;key: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#183-190" title="goto source code">[src]</a></h4><h4 id="method.end" class="method hidden"><code>fn <a href="#method.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Ok, Error&gt;</code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#192-194" title="goto source code">[src]</a></h4></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/ser/trait.SerializeStruct.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
@@ -0,0 +1,49 @@
<!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="Returned from `Serializer::serialize_struct_variant`."><meta name="keywords" content="rust, rustlang, rust-lang, SerializeStructVariant"><title>serde::ser::SerializeStructVariant - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait SerializeStructVariant</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Error">Error</a><a href="#associatedtype.Ok">Ok</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.end">end</a><a href="#tymethod.serialize_field">serialize_field</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.skip_field">skip_field</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a></p><div id="sidebar-vars" data-name="SerializeStructVariant" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a>::<wbr><a class="trait" href="">SerializeStructVariant</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/ser/mod.rs.html#1929-1954" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait SerializeStructVariant {
type <a href="#associatedtype.Ok" class="type">Ok</a>;
type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>;
fn <a href="#tymethod.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStructVariant.html#associatedtype.Error" title="type serde::ser::SerializeStructVariant::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a></span>;
<div class="item-spacer"></div> fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeStructVariant.html#associatedtype.Ok" title="type serde::ser::SerializeStructVariant::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStructVariant.html#associatedtype.Error" title="type serde::ser::SerializeStructVariant::Error">Error</a>&gt;;
fn <a href="#method.skip_field" class="fnname">skip_field</a>(&amp;mut self, key: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStructVariant.html#associatedtype.Error" title="type serde::ser::SerializeStructVariant::Error">Error</a>&gt; { ... }
}</pre></div><div class="docblock"><p>Returned from <code>Serializer::serialize_struct_variant</code>.</p>
<h1 id="example-use" class="section-header"><a href="#example-use">Example use</a></h1>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">ser</span>::{<span class="ident">Serialize</span>, <span class="ident">SerializeStructVariant</span>, <span class="ident">Serializer</span>};
<span class="kw">enum</span> <span class="ident">E</span> {
<span class="ident">S</span> { <span class="ident">r</span>: <span class="ident">u8</span>, <span class="ident">g</span>: <span class="ident">u8</span>, <span class="ident">b</span>: <span class="ident">u8</span> },
}
<span class="kw">impl</span> <span class="ident">Serialize</span> <span class="kw">for</span> <span class="ident">E</span> {
<span class="kw">fn</span> <span class="ident">serialize</span><span class="op">&lt;</span><span class="ident">S</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">serializer</span>: <span class="ident">S</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">S</span>::<span class="prelude-val">Ok</span>, <span class="ident">S</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">S</span>: <span class="ident">Serializer</span>,
{
<span class="kw">match</span> <span class="kw-2">*</span><span class="self">self</span> {
<span class="ident">E</span>::<span class="ident">S</span> {
<span class="kw-2">ref</span> <span class="ident">r</span>,
<span class="kw-2">ref</span> <span class="ident">g</span>,
<span class="kw-2">ref</span> <span class="ident">b</span>,
} <span class="op">=</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">sv</span> <span class="op">=</span> <span class="ident">serializer</span>.<span class="ident">serialize_struct_variant</span>(<span class="string">&quot;E&quot;</span>, <span class="number">0</span>, <span class="string">&quot;S&quot;</span>, <span class="number">3</span>)<span class="question-mark">?</span>;
<span class="ident">sv</span>.<span class="ident">serialize_field</span>(<span class="string">&quot;r&quot;</span>, <span class="ident">r</span>)<span class="question-mark">?</span>;
<span class="ident">sv</span>.<span class="ident">serialize_field</span>(<span class="string">&quot;g&quot;</span>, <span class="ident">g</span>)<span class="question-mark">?</span>;
<span class="ident">sv</span>.<span class="ident">serialize_field</span>(<span class="string">&quot;b&quot;</span>, <span class="ident">b</span>)<span class="question-mark">?</span>;
<span class="ident">sv</span>.<span class="ident">end</span>()
}
}
}
}</pre></div>
<h1 id="example-implementation" class="section-header"><a href="#example-implementation">Example implementation</a></h1>
<p>The <a href="https://serde.rs/data-format.html">example data format</a> presented on the website demonstrates an
implementation of <code>SerializeStructVariant</code> for a basic JSON data format.</p>
</div><h2 id="associated-types" class="small-section-header">Associated Types<a href="#associated-types" class="anchor"></a></h2><div class="methods"><h3 id="associatedtype.Ok" class="method"><code>type <a href="#associatedtype.Ok" class="type">Ok</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1931" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Ok</code> type of our <code>Serializer</code>.</p>
</div><h3 id="associatedtype.Error" class="method"><code>type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1934" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Error</code> type of our <code>Serializer</code>.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.serialize_field" class="method"><code>fn <a href="#tymethod.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;key: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStructVariant.html#associatedtype.Error" title="type serde::ser::SerializeStructVariant::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1937-1943" title="goto source code">[src]</a></h3><div class="docblock"><p>Serialize a struct variant field.</p>
</div><h3 id="tymethod.end" class="method"><code>fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeStructVariant.html#associatedtype.Ok" title="type serde::ser::SerializeStructVariant::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStructVariant.html#associatedtype.Error" title="type serde::ser::SerializeStructVariant::Error">Error</a>&gt;</code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1953" title="goto source code">[src]</a></h3><div class="docblock"><p>Finish serializing a struct variant.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="provided-methods" class="small-section-header">Provided methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><h3 id="method.skip_field" class="method"><code>fn <a href="#method.skip_field" class="fnname">skip_field</a>(&amp;mut self, key: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeStructVariant.html#associatedtype.Error" title="type serde::ser::SerializeStructVariant::Error">Error</a>&gt;</code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1947-1950" title="goto source code">[src]</a></h3><div class="docblock"><p>Indicate that a struct variant field has been skipped.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-SerializeStructVariant" class="impl"><code class="in-band">impl&lt;Ok, Error&gt; <a class="trait" href="../../serde/ser/trait.SerializeStructVariant.html" title="trait serde::ser::SerializeStructVariant">SerializeStructVariant</a> for <a class="struct" href="../../serde/ser/struct.Impossible.html" title="struct serde::ser::Impossible">Impossible</a>&lt;Ok, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Error: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>,&nbsp;</span></code><a href="#impl-SerializeStructVariant" class="anchor"></a><a class="srclink" href="../../src/serde/ser/impossible.rs.html#197-216" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Ok-1" class="type"><code>type <a href="#associatedtype.Ok-1" class="type">Ok</a> = Ok</code></h4><h4 id="associatedtype.Error-1" class="type"><code>type <a href="#associatedtype.Error-1" class="type">Error</a> = Error</code></h4><h4 id="method.serialize_field" class="method hidden"><code>fn <a href="#method.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;key: &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#204-211" title="goto source code">[src]</a></h4><h4 id="method.end" class="method hidden"><code>fn <a href="#method.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Ok, Error&gt;</code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#213-215" title="goto source code">[src]</a></h4></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/ser/trait.SerializeStructVariant.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
+58
View File
@@ -0,0 +1,58 @@
<!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="Returned from `Serializer::serialize_tuple`."><meta name="keywords" content="rust, rustlang, rust-lang, SerializeTuple"><title>serde::ser::SerializeTuple - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait SerializeTuple</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Error">Error</a><a href="#associatedtype.Ok">Ok</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.end">end</a><a href="#tymethod.serialize_element">serialize_element</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a></p><div id="sidebar-vars" data-name="SerializeTuple" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a>::<wbr><a class="trait" href="">SerializeTuple</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/ser/mod.rs.html#1600-1614" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait SerializeTuple {
type <a href="#associatedtype.Ok" class="type">Ok</a>;
type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>;
fn <a href="#tymethod.serialize_element" class="fnname">serialize_element</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTuple.html#associatedtype.Error" title="type serde::ser::SerializeTuple::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a></span>;
<div class="item-spacer"></div> fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeTuple.html#associatedtype.Ok" title="type serde::ser::SerializeTuple::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTuple.html#associatedtype.Error" title="type serde::ser::SerializeTuple::Error">Error</a>&gt;;
}</pre></div><div class="docblock"><p>Returned from <code>Serializer::serialize_tuple</code>.</p>
<h1 id="example-use" class="section-header"><a href="#example-use">Example use</a></h1>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">ser</span>::{<span class="ident">Serialize</span>, <span class="ident">Serializer</span>, <span class="ident">SerializeTuple</span>};
<span class="kw">impl</span><span class="op">&lt;</span><span class="ident">A</span>, <span class="ident">B</span>, <span class="ident">C</span><span class="op">&gt;</span> <span class="ident">Serialize</span> <span class="kw">for</span> (<span class="ident">A</span>, <span class="ident">B</span>, <span class="ident">C</span>)
<span class="kw">where</span>
<span class="ident">A</span>: <span class="ident">Serialize</span>,
<span class="ident">B</span>: <span class="ident">Serialize</span>,
<span class="ident">C</span>: <span class="ident">Serialize</span>,
{
<span class="kw">fn</span> <span class="ident">serialize</span><span class="op">&lt;</span><span class="ident">S</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">serializer</span>: <span class="ident">S</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">S</span>::<span class="prelude-val">Ok</span>, <span class="ident">S</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">S</span>: <span class="ident">Serializer</span>,
{
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">tup</span> <span class="op">=</span> <span class="ident">serializer</span>.<span class="ident">serialize_tuple</span>(<span class="number">3</span>)<span class="question-mark">?</span>;
<span class="ident">tup</span>.<span class="ident">serialize_element</span>(<span class="kw-2">&amp;</span><span class="self">self</span>.<span class="number">0</span>)<span class="question-mark">?</span>;
<span class="ident">tup</span>.<span class="ident">serialize_element</span>(<span class="kw-2">&amp;</span><span class="self">self</span>.<span class="number">1</span>)<span class="question-mark">?</span>;
<span class="ident">tup</span>.<span class="ident">serialize_element</span>(<span class="kw-2">&amp;</span><span class="self">self</span>.<span class="number">2</span>)<span class="question-mark">?</span>;
<span class="ident">tup</span>.<span class="ident">end</span>()
}
}</pre></div>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">ser</span>::{<span class="ident">Serialize</span>, <span class="ident">Serializer</span>, <span class="ident">SerializeTuple</span>};
<span class="kw">impl</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span> <span class="ident">Serialize</span> <span class="kw">for</span> [<span class="ident">T</span>; <span class="number">16</span>]
<span class="kw">where</span>
<span class="ident">T</span>: <span class="ident">Serialize</span>,
{
<span class="kw">fn</span> <span class="ident">serialize</span><span class="op">&lt;</span><span class="ident">S</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">serializer</span>: <span class="ident">S</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">S</span>::<span class="prelude-val">Ok</span>, <span class="ident">S</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">S</span>: <span class="ident">Serializer</span>,
{
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">seq</span> <span class="op">=</span> <span class="ident">serializer</span>.<span class="ident">serialize_tuple</span>(<span class="number">16</span>)<span class="question-mark">?</span>;
<span class="kw">for</span> <span class="ident">element</span> <span class="kw">in</span> <span class="self">self</span> {
<span class="ident">seq</span>.<span class="ident">serialize_element</span>(<span class="ident">element</span>)<span class="question-mark">?</span>;
}
<span class="ident">seq</span>.<span class="ident">end</span>()
}
}</pre></div>
<h1 id="example-implementation" class="section-header"><a href="#example-implementation">Example implementation</a></h1>
<p>The <a href="https://serde.rs/data-format.html">example data format</a> presented on the website demonstrates an
implementation of <code>SerializeTuple</code> for a basic JSON data format.</p>
</div><h2 id="associated-types" class="small-section-header">Associated Types<a href="#associated-types" class="anchor"></a></h2><div class="methods"><h3 id="associatedtype.Ok" class="method"><code>type <a href="#associatedtype.Ok" class="type">Ok</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1602" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Ok</code> type of our <code>Serializer</code>.</p>
</div><h3 id="associatedtype.Error" class="method"><code>type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1605" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Error</code> type of our <code>Serializer</code>.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.serialize_element" class="method"><code>fn <a href="#tymethod.serialize_element" class="fnname">serialize_element</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTuple.html#associatedtype.Error" title="type serde::ser::SerializeTuple::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1608-1610" title="goto source code">[src]</a></h3><div class="docblock"><p>Serialize a tuple element.</p>
</div><h3 id="tymethod.end" class="method"><code>fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeTuple.html#associatedtype.Ok" title="type serde::ser::SerializeTuple::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTuple.html#associatedtype.Error" title="type serde::ser::SerializeTuple::Error">Error</a>&gt;</code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1613" title="goto source code">[src]</a></h3><div class="docblock"><p>Finish serializing a tuple.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-SerializeTuple" class="impl"><code class="in-band">impl&lt;Ok, Error&gt; <a class="trait" href="../../serde/ser/trait.SerializeTuple.html" title="trait serde::ser::SerializeTuple">SerializeTuple</a> for <a class="struct" href="../../serde/ser/struct.Impossible.html" title="struct serde::ser::Impossible">Impossible</a>&lt;Ok, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Error: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>,&nbsp;</span></code><a href="#impl-SerializeTuple" class="anchor"></a><a class="srclink" href="../../src/serde/ser/impossible.rs.html#88-106" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Ok-1" class="type"><code>type <a href="#associatedtype.Ok-1" class="type">Ok</a> = Ok</code></h4><h4 id="associatedtype.Error-1" class="type"><code>type <a href="#associatedtype.Error-1" class="type">Error</a> = Error</code></h4><h4 id="method.serialize_element" class="method hidden"><code>fn <a href="#method.serialize_element" class="fnname">serialize_element</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#95-101" title="goto source code">[src]</a></h4><h4 id="method.end" class="method hidden"><code>fn <a href="#method.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Ok, Error&gt;</code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#103-105" title="goto source code">[src]</a></h4></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/ser/trait.SerializeTuple.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
@@ -0,0 +1,36 @@
<!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="Returned from `Serializer::serialize_tuple_struct`."><meta name="keywords" content="rust, rustlang, rust-lang, SerializeTupleStruct"><title>serde::ser::SerializeTupleStruct - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait SerializeTupleStruct</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Error">Error</a><a href="#associatedtype.Ok">Ok</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.end">end</a><a href="#tymethod.serialize_field">serialize_field</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a></p><div id="sidebar-vars" data-name="SerializeTupleStruct" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a>::<wbr><a class="trait" href="">SerializeTupleStruct</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/ser/mod.rs.html#1645-1659" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait SerializeTupleStruct {
type <a href="#associatedtype.Ok" class="type">Ok</a>;
type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>;
fn <a href="#tymethod.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTupleStruct.html#associatedtype.Error" title="type serde::ser::SerializeTupleStruct::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a></span>;
<div class="item-spacer"></div> fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeTupleStruct.html#associatedtype.Ok" title="type serde::ser::SerializeTupleStruct::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTupleStruct.html#associatedtype.Error" title="type serde::ser::SerializeTupleStruct::Error">Error</a>&gt;;
}</pre></div><div class="docblock"><p>Returned from <code>Serializer::serialize_tuple_struct</code>.</p>
<h1 id="example-use" class="section-header"><a href="#example-use">Example use</a></h1>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">ser</span>::{<span class="ident">Serialize</span>, <span class="ident">SerializeTupleStruct</span>, <span class="ident">Serializer</span>};
<span class="kw">struct</span> <span class="ident">Rgb</span>(<span class="ident">u8</span>, <span class="ident">u8</span>, <span class="ident">u8</span>);
<span class="kw">impl</span> <span class="ident">Serialize</span> <span class="kw">for</span> <span class="ident">Rgb</span> {
<span class="kw">fn</span> <span class="ident">serialize</span><span class="op">&lt;</span><span class="ident">S</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">serializer</span>: <span class="ident">S</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">S</span>::<span class="prelude-val">Ok</span>, <span class="ident">S</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">S</span>: <span class="ident">Serializer</span>,
{
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">ts</span> <span class="op">=</span> <span class="ident">serializer</span>.<span class="ident">serialize_tuple_struct</span>(<span class="string">&quot;Rgb&quot;</span>, <span class="number">3</span>)<span class="question-mark">?</span>;
<span class="ident">ts</span>.<span class="ident">serialize_field</span>(<span class="kw-2">&amp;</span><span class="self">self</span>.<span class="number">0</span>)<span class="question-mark">?</span>;
<span class="ident">ts</span>.<span class="ident">serialize_field</span>(<span class="kw-2">&amp;</span><span class="self">self</span>.<span class="number">1</span>)<span class="question-mark">?</span>;
<span class="ident">ts</span>.<span class="ident">serialize_field</span>(<span class="kw-2">&amp;</span><span class="self">self</span>.<span class="number">2</span>)<span class="question-mark">?</span>;
<span class="ident">ts</span>.<span class="ident">end</span>()
}
}</pre></div>
<h1 id="example-implementation" class="section-header"><a href="#example-implementation">Example implementation</a></h1>
<p>The <a href="https://serde.rs/data-format.html">example data format</a> presented on the website demonstrates an
implementation of <code>SerializeTupleStruct</code> for a basic JSON data format.</p>
</div><h2 id="associated-types" class="small-section-header">Associated Types<a href="#associated-types" class="anchor"></a></h2><div class="methods"><h3 id="associatedtype.Ok" class="method"><code>type <a href="#associatedtype.Ok" class="type">Ok</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1647" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Ok</code> type of our <code>Serializer</code>.</p>
</div><h3 id="associatedtype.Error" class="method"><code>type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1650" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Error</code> type of our <code>Serializer</code>.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.serialize_field" class="method"><code>fn <a href="#tymethod.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTupleStruct.html#associatedtype.Error" title="type serde::ser::SerializeTupleStruct::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1653-1655" title="goto source code">[src]</a></h3><div class="docblock"><p>Serialize a tuple struct field.</p>
</div><h3 id="tymethod.end" class="method"><code>fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeTupleStruct.html#associatedtype.Ok" title="type serde::ser::SerializeTupleStruct::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTupleStruct.html#associatedtype.Error" title="type serde::ser::SerializeTupleStruct::Error">Error</a>&gt;</code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1658" title="goto source code">[src]</a></h3><div class="docblock"><p>Finish serializing a tuple struct.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-SerializeTupleStruct" class="impl"><code class="in-band">impl&lt;Ok, Error&gt; <a class="trait" href="../../serde/ser/trait.SerializeTupleStruct.html" title="trait serde::ser::SerializeTupleStruct">SerializeTupleStruct</a> for <a class="struct" href="../../serde/ser/struct.Impossible.html" title="struct serde::ser::Impossible">Impossible</a>&lt;Ok, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Error: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>,&nbsp;</span></code><a href="#impl-SerializeTupleStruct" class="anchor"></a><a class="srclink" href="../../src/serde/ser/impossible.rs.html#108-126" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Ok-1" class="type"><code>type <a href="#associatedtype.Ok-1" class="type">Ok</a> = Ok</code></h4><h4 id="associatedtype.Error-1" class="type"><code>type <a href="#associatedtype.Error-1" class="type">Error</a> = Error</code></h4><h4 id="method.serialize_field" class="method hidden"><code>fn <a href="#method.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#115-121" title="goto source code">[src]</a></h4><h4 id="method.end" class="method hidden"><code>fn <a href="#method.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Ok, Error&gt;</code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#123-125" title="goto source code">[src]</a></h4></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/ser/trait.SerializeTupleStruct.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
@@ -0,0 +1,49 @@
<!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="Returned from `Serializer::serialize_tuple_variant`."><meta name="keywords" content="rust, rustlang, rust-lang, SerializeTupleVariant"><title>serde::ser::SerializeTupleVariant - 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 trait"><!--[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">&#9776;</div><a href='../../serde/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait SerializeTupleVariant</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Error">Error</a><a href="#associatedtype.Ok">Ok</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.end">end</a><a href="#tymethod.serialize_field">serialize_field</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a></p><div id="sidebar-vars" data-name="SerializeTupleVariant" data-ty="trait" 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" 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="in-band">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">ser</a>::<wbr><a class="trait" href="">SerializeTupleVariant</a></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">&#x2212;</span>]</a></span><a class="srclink" href="../../src/serde/ser/mod.rs.html#1703-1717" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait SerializeTupleVariant {
type <a href="#associatedtype.Ok" class="type">Ok</a>;
type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>;
fn <a href="#tymethod.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTupleVariant.html#associatedtype.Error" title="type serde::ser::SerializeTupleVariant::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a></span>;
<div class="item-spacer"></div> fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeTupleVariant.html#associatedtype.Ok" title="type serde::ser::SerializeTupleVariant::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTupleVariant.html#associatedtype.Error" title="type serde::ser::SerializeTupleVariant::Error">Error</a>&gt;;
}</pre></div><div class="docblock"><p>Returned from <code>Serializer::serialize_tuple_variant</code>.</p>
<h1 id="example-use" class="section-header"><a href="#example-use">Example use</a></h1>
<div class='information'><div class='tooltip edition' data-edition="2018"></div></div><div class="example-wrap"><pre class="rust rust-example-rendered edition">
<span class="kw">use</span> <span class="ident">serde</span>::<span class="ident">ser</span>::{<span class="ident">Serialize</span>, <span class="ident">SerializeTupleVariant</span>, <span class="ident">Serializer</span>};
<span class="kw">enum</span> <span class="ident">E</span> {
<span class="ident">T</span>(<span class="ident">u8</span>, <span class="ident">u8</span>),
<span class="ident">U</span>(<span class="ident">String</span>, <span class="ident">u32</span>, <span class="ident">u32</span>),
}
<span class="kw">impl</span> <span class="ident">Serialize</span> <span class="kw">for</span> <span class="ident">E</span> {
<span class="kw">fn</span> <span class="ident">serialize</span><span class="op">&lt;</span><span class="ident">S</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">serializer</span>: <span class="ident">S</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">S</span>::<span class="prelude-val">Ok</span>, <span class="ident">S</span>::<span class="ident">Error</span><span class="op">&gt;</span>
<span class="kw">where</span>
<span class="ident">S</span>: <span class="ident">Serializer</span>,
{
<span class="kw">match</span> <span class="kw-2">*</span><span class="self">self</span> {
<span class="ident">E</span>::<span class="ident">T</span>(<span class="kw-2">ref</span> <span class="ident">a</span>, <span class="kw-2">ref</span> <span class="ident">b</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">tv</span> <span class="op">=</span> <span class="ident">serializer</span>.<span class="ident">serialize_tuple_variant</span>(<span class="string">&quot;E&quot;</span>, <span class="number">0</span>, <span class="string">&quot;T&quot;</span>, <span class="number">2</span>)<span class="question-mark">?</span>;
<span class="ident">tv</span>.<span class="ident">serialize_field</span>(<span class="ident">a</span>)<span class="question-mark">?</span>;
<span class="ident">tv</span>.<span class="ident">serialize_field</span>(<span class="ident">b</span>)<span class="question-mark">?</span>;
<span class="ident">tv</span>.<span class="ident">end</span>()
}
<span class="ident">E</span>::<span class="ident">U</span>(<span class="kw-2">ref</span> <span class="ident">a</span>, <span class="kw-2">ref</span> <span class="ident">b</span>, <span class="kw-2">ref</span> <span class="ident">c</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">tv</span> <span class="op">=</span> <span class="ident">serializer</span>.<span class="ident">serialize_tuple_variant</span>(<span class="string">&quot;E&quot;</span>, <span class="number">1</span>, <span class="string">&quot;U&quot;</span>, <span class="number">3</span>)<span class="question-mark">?</span>;
<span class="ident">tv</span>.<span class="ident">serialize_field</span>(<span class="ident">a</span>)<span class="question-mark">?</span>;
<span class="ident">tv</span>.<span class="ident">serialize_field</span>(<span class="ident">b</span>)<span class="question-mark">?</span>;
<span class="ident">tv</span>.<span class="ident">serialize_field</span>(<span class="ident">c</span>)<span class="question-mark">?</span>;
<span class="ident">tv</span>.<span class="ident">end</span>()
}
}
}
}</pre></div>
<h1 id="example-implementation" class="section-header"><a href="#example-implementation">Example implementation</a></h1>
<p>The <a href="https://serde.rs/data-format.html">example data format</a> presented on the website demonstrates an
implementation of <code>SerializeTupleVariant</code> for a basic JSON data format.</p>
</div><h2 id="associated-types" class="small-section-header">Associated Types<a href="#associated-types" class="anchor"></a></h2><div class="methods"><h3 id="associatedtype.Ok" class="method"><code>type <a href="#associatedtype.Ok" class="type">Ok</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1705" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Ok</code> type of our <code>Serializer</code>.</p>
</div><h3 id="associatedtype.Error" class="method"><code>type <a href="#associatedtype.Error" class="type">Error</a>: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1708" title="goto source code">[src]</a></h3><div class="docblock"><p>Must match the <code>Error</code> type of our <code>Serializer</code>.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.serialize_field" class="method"><code>fn <a href="#tymethod.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTupleVariant.html#associatedtype.Error" title="type serde::ser::SerializeTupleVariant::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1711-1713" title="goto source code">[src]</a></h3><div class="docblock"><p>Serialize a tuple variant field.</p>
</div><h3 id="tymethod.end" class="method"><code>fn <a href="#tymethod.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="type" href="../../serde/ser/trait.SerializeTupleVariant.html#associatedtype.Ok" title="type serde::ser::SerializeTupleVariant::Ok">Ok</a>, Self::<a class="type" href="../../serde/ser/trait.SerializeTupleVariant.html#associatedtype.Error" title="type serde::ser::SerializeTupleVariant::Error">Error</a>&gt;</code><a class="srclink" href="../../src/serde/ser/mod.rs.html#1716" title="goto source code">[src]</a></h3><div class="docblock"><p>Finish serializing a tuple variant.</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-SerializeTupleVariant" class="impl"><code class="in-band">impl&lt;Ok, Error&gt; <a class="trait" href="../../serde/ser/trait.SerializeTupleVariant.html" title="trait serde::ser::SerializeTupleVariant">SerializeTupleVariant</a> for <a class="struct" href="../../serde/ser/struct.Impossible.html" title="struct serde::ser::Impossible">Impossible</a>&lt;Ok, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Error: <a class="trait" href="../../serde/ser/trait.Error.html" title="trait serde::ser::Error">Error</a>,&nbsp;</span></code><a href="#impl-SerializeTupleVariant" class="anchor"></a><a class="srclink" href="../../src/serde/ser/impossible.rs.html#128-146" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Ok-1" class="type"><code>type <a href="#associatedtype.Ok-1" class="type">Ok</a> = Ok</code></h4><h4 id="associatedtype.Error-1" class="type"><code>type <a href="#associatedtype.Error-1" class="type">Error</a> = Error</code></h4><h4 id="method.serialize_field" class="method hidden"><code>fn <a href="#method.serialize_field" class="fnname">serialize_field</a>&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../serde/trait.Serialize.html" title="trait serde::Serialize">Serialize</a>,&nbsp;</span></code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#135-141" title="goto source code">[src]</a></h4><h4 id="method.end" class="method hidden"><code>fn <a href="#method.end" class="fnname">end</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Ok, Error&gt;</code><a class="srclink" href="../../src/serde/ser/impossible.rs.html#143-145" title="goto source code">[src]</a></h4></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/serde/ser/trait.SerializeTupleVariant.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde"></div>
<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
+1
View File
@@ -0,0 +1 @@
initSidebarItems({"macro":[["forward_to_deserialize_any","Helper macro when implementing the `Deserializer` part of a new data format for Serde."],["serde_if_integer128","Conditional compilation depending on whether Serde is built with support for 128-bit integers."]],"mod":[["de","Generic data structure deserialization framework."],["ser","Generic data structure serialization framework."]],"trait":[["Deserialize","A data structure that can be deserialized from any data format supported by Serde."],["Deserializer","A data format that can deserialize any data structure supported by Serde."],["Serialize","A data structure that can be serialized into any data format supported by Serde."],["Serializer","A data format that can serialize any data structure supported by Serde."]]});
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