156 lines
15 KiB
HTML
156 lines
15 KiB
HTML
<!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="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><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="../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script src="../../crates.js"></script><script defer src="../../main.js"></script>
|
||
<noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a class="sidebar-logo" href="../../serde/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.png" alt="logo"></div>
|
||
</a><h2 class="location">Module de</h2><div class="sidebar-elems"><div class="block items"><ul><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><div id="sidebar-vars" data-name="de" data-ty="mod" data-relpath="./"></div><script defer src="./sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../serde/index.html"><img class="rust-logo" src="../../rust-logo.png" alt="logo"></a><nav class="sub"><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="18" height="18" alt="Pick another theme!" src="../../brush.svg"></button><div id="theme-choices" role="menu"></div></div><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" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../../settings.html" title="settings"><img width="18" height="18" alt="Change settings" src="../../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><h1 class="fqn"><span class="in-band">Module <a href="../index.html">serde</a>::<wbr><a class="mod" href="#">de</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../../src/serde/de/mod.rs.html#1-2295" title="goto source code">[src]</a></span></h1><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><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>
|
||
<h2 id="the-deserialize-trait" class="section-header"><a href="#the-deserialize-trait">The Deserialize trait</a></h2>
|
||
<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<K, V></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>
|
||
<h2 id="the-deserializer-trait" class="section-header"><a href="#the-deserializer-trait">The Deserializer trait</a></h2>
|
||
<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>
|
||
<h2 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></h2>
|
||
<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<T></li>
|
||
<li>Result<T, E></li>
|
||
<li>PhantomData<T></li>
|
||
</ul>
|
||
</li>
|
||
<li><strong>Wrapper types</strong>:
|
||
<ul>
|
||
<li>Box<T></li>
|
||
<li>Box<[T]></li>
|
||
<li>Box<str></li>
|
||
<li>Cow<’a, T></li>
|
||
<li>Cell<T></li>
|
||
<li>RefCell<T></li>
|
||
<li>Mutex<T></li>
|
||
<li>RwLock<T></li>
|
||
<li>Rc<T> <em>(if</em> features = [“rc”] <em>is enabled)</em></li>
|
||
<li>Arc<T> <em>(if</em> features = [“rc”] <em>is enabled)</em></li>
|
||
</ul>
|
||
</li>
|
||
<li><strong>Collection types</strong>:
|
||
<ul>
|
||
<li>BTreeMap<K, V></li>
|
||
<li>BTreeSet<T></li>
|
||
<li>BinaryHeap<T></li>
|
||
<li>HashMap<K, V, H></li>
|
||
<li>HashSet<T, H></li>
|
||
<li>LinkedList<T></li>
|
||
<li>VecDeque<T></li>
|
||
<li>Vec<T></li>
|
||
</ul>
|
||
</li>
|
||
<li><strong>Zero-copy types</strong>:
|
||
<ul>
|
||
<li>&str</li>
|
||
<li>&[u8]</li>
|
||
</ul>
|
||
</li>
|
||
<li><strong>FFI types</strong>:
|
||
<ul>
|
||
<li>CString</li>
|
||
<li>Box<CStr></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<T></li>
|
||
<li>RangeInclusive<T></li>
|
||
<li>Bound<T></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></details><h2 id="reexports" class="small-section-header"><a href="#reexports">Re-exports</a></h2>
|
||
<div class="item-table"><div class="item-row"><div class="item-left import-item"><code>pub use std::error::<a class="trait" href="https://doc.rust-lang.org/1.59.0/std/error/trait.Error.html" title="trait std::error::Error">Error</a> as StdError;</code></div><div class="item-right docblock-short"></div></div></div><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2>
|
||
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="value/index.html" title="serde::de::value mod">value</a></div><div class="item-right docblock-short"><p>Building blocks for deserializing basic values using the <code>IntoDeserializer</code>
|
||
trait.</p>
|
||
</div></div></div><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2>
|
||
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.IgnoredAny.html" title="serde::de::IgnoredAny struct">IgnoredAny</a></div><div class="item-right docblock-short"><p>An efficient way of discarding data from a deserializer.</p>
|
||
</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2>
|
||
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Unexpected.html" title="serde::de::Unexpected enum">Unexpected</a></div><div class="item-right docblock-short"><p><code>Unexpected</code> represents an unexpected invocation of any one of the <code>Visitor</code>
|
||
trait methods.</p>
|
||
</div></div></div><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2>
|
||
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Deserialize.html" title="serde::de::Deserialize trait">Deserialize</a></div><div class="item-right docblock-short"><p>A <strong>data structure</strong> that can be deserialized from any data format supported
|
||
by Serde.</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.DeserializeOwned.html" title="serde::de::DeserializeOwned trait">DeserializeOwned</a></div><div class="item-right docblock-short"><p>A data structure that can be deserialized without borrowing any data from
|
||
the deserializer.</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.DeserializeSeed.html" title="serde::de::DeserializeSeed trait">DeserializeSeed</a></div><div class="item-right 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>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Deserializer.html" title="serde::de::Deserializer trait">Deserializer</a></div><div class="item-right docblock-short"><p>A <strong>data format</strong> that can deserialize any data structure supported by
|
||
Serde.</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.EnumAccess.html" title="serde::de::EnumAccess trait">EnumAccess</a></div><div class="item-right docblock-short"><p>Provides a <code>Visitor</code> access to the data of an enum in the input.</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Error.html" title="serde::de::Error trait">Error</a></div><div class="item-right 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>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Expected.html" title="serde::de::Expected trait">Expected</a></div><div class="item-right docblock-short"><p><code>Expected</code> represents an explanation of what data a <code>Visitor</code> was expecting
|
||
to receive.</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.IntoDeserializer.html" title="serde::de::IntoDeserializer trait">IntoDeserializer</a></div><div class="item-right docblock-short"><p>Converts an existing value into a <code>Deserializer</code> from which other values can
|
||
be deserialized.</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.MapAccess.html" title="serde::de::MapAccess trait">MapAccess</a></div><div class="item-right docblock-short"><p>Provides a <code>Visitor</code> access to each entry of a map in the input.</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.SeqAccess.html" title="serde::de::SeqAccess trait">SeqAccess</a></div><div class="item-right docblock-short"><p>Provides a <code>Visitor</code> access to each element of a sequence in the input.</p>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.VariantAccess.html" title="serde::de::VariantAccess trait">VariantAccess</a></div><div class="item-right 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>
|
||
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Visitor.html" title="serde::de::Visitor trait">Visitor</a></div><div class="item-right docblock-short"><p>This trait represents a visitor that walks through a deserializer.</p>
|
||
</div></div></div></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="serde" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.59.0 (9d1b2106e 2022-02-23)" ></div>
|
||
</body></html> |