315 lines
14 KiB
HTML
315 lines
14 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="API documentation for the Rust `ser` mod in crate `serde`.">
|
|||
|
<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">
|
|||
|
<link rel="stylesheet" type="text/css" href="../../main.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</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">
|
|||
|
|
|||
|
<p class='location'>Module ser</p><div class="block items"><ul><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><script>window.sidebarCurrent = {name: 'ser', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></script>
|
|||
|
</nav>
|
|||
|
|
|||
|
<nav class="sub">
|
|||
|
<form class="search-form js-only">
|
|||
|
<div class="search-container">
|
|||
|
<input class="search-input" name="search"
|
|||
|
autocomplete="off"
|
|||
|
placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
|
|||
|
type="search">
|
|||
|
</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'>−</span>]
|
|||
|
</a>
|
|||
|
</span><a class='srclink' href='../../src/serde/ser/mod.rs.html#9-1816' 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/codegen.html">codegen 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<K, V></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/TyOverby/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, isize</li>
|
|||
|
<li>u8, u16, u32, u64, usize</li>
|
|||
|
<li>f32, f64</li>
|
|||
|
<li>char</li>
|
|||
|
<li>str</li>
|
|||
|
<li>&T and &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<T></li>
|
|||
|
<li>Result<T, E></li>
|
|||
|
<li>PhantomData<T></li>
|
|||
|
</ul></li>
|
|||
|
<li><strong>Wrapper types</strong>:
|
|||
|
|
|||
|
<ul>
|
|||
|
<li>Box<T></li>
|
|||
|
<li>Rc<T></li>
|
|||
|
<li>Arc<T></li>
|
|||
|
<li>Cow<'a, T></li>
|
|||
|
<li>Cell<T></li>
|
|||
|
<li>RefCell<T></li>
|
|||
|
<li>Mutex<T></li>
|
|||
|
<li>RwLock<T></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>
|
|||
|
<li>EnumSet<T> (unstable)</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<T></li>
|
|||
|
<li>NonZero<T> (unstable)</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='structs' class='section-header'><a href="#structs">Structs</a></h2>
|
|||
|
<table>
|
|||
|
<tr class=' module-item'>
|
|||
|
<td><a class="struct" href="struct.Impossible.html"
|
|||
|
title='struct serde::ser::Impossible'>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='trait serde::ser::Error'>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='trait serde::ser::Serialize'>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='trait serde::ser::SerializeMap'>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='trait serde::ser::SerializeSeq'>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='trait serde::ser::SerializeStruct'>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='trait serde::ser::SerializeStructVariant'>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='trait serde::ser::SerializeTuple'>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='trait serde::ser::SerializeTupleStruct'>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='trait serde::ser::SerializeTupleVariant'>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='trait serde::ser::Serializer'>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>
|
|||
|
|
|||
|
<aside id="help" class="hidden">
|
|||
|
<div>
|
|||
|
<h1 class="hidden">Help</h1>
|
|||
|
|
|||
|
<div class="shortcuts">
|
|||
|
<h2>Keyboard Shortcuts</h2>
|
|||
|
|
|||
|
<dl>
|
|||
|
<dt>?</dt>
|
|||
|
<dd>Show this help dialog</dd>
|
|||
|
<dt>S</dt>
|
|||
|
<dd>Focus the search field</dd>
|
|||
|
<dt>⇤</dt>
|
|||
|
<dd>Move up in search results</dd>
|
|||
|
<dt>⇥</dt>
|
|||
|
<dd>Move down in search results</dd>
|
|||
|
<dt>⏎</dt>
|
|||
|
<dd>Go to active search result</dd>
|
|||
|
<dt>+</dt>
|
|||
|
<dd>Collapse/expand all sections</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="infos">
|
|||
|
<h2>Search Tricks</h2>
|
|||
|
|
|||
|
<p>
|
|||
|
Prefix searches with a type followed by a colon (e.g.
|
|||
|
<code>fn:</code>) to restrict the search to a given type.
|
|||
|
</p>
|
|||
|
|
|||
|
<p>
|
|||
|
Accepted types are: <code>fn</code>, <code>mod</code>,
|
|||
|
<code>struct</code>, <code>enum</code>,
|
|||
|
<code>trait</code>, <code>type</code>, <code>macro</code>,
|
|||
|
and <code>const</code>.
|
|||
|
</p>
|
|||
|
|
|||
|
<p>
|
|||
|
Search functions by type signature (e.g.
|
|||
|
<code>vec -> usize</code> or <code>* -> vec</code>)
|
|||
|
</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</aside>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script>
|
|||
|
window.rootPath = "../../";
|
|||
|
window.currentCrate = "serde";
|
|||
|
</script>
|
|||
|
<script src="../../main.js"></script>
|
|||
|
<script defer src="../../search-index.js"></script>
|
|||
|
</body>
|
|||
|
</html>
|