|
|
|
|
<!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 `serde` crate."><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="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../serde/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Crate serde</p><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><script>window.sidebarCurrent = {name: 'serde', ty: 'mod', relpath: '../'};</script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><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><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>−</span>]</a></span><a class='srclink' href='../src/serde/lib.rs.html#1-262' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>serde</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 Rust's powerful trait system. A data structure
|
|
|
|
|
that knows how to serialize and deserialize itself is one that implements
|
|
|
|
|
Serde's <code>Serialize</code> and <code>Deserialize</code> traits (or uses Serde's 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/TyOverby/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 popular human-friendly configuration language that ain't 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/nox/serde_urlencoded">URL</a>, 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>
|
|
|
|
|
</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><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>⏎</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse 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><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "serde";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|