blob: b4ea4cb8dcc2fd27c6c111d41bb88cf736bcca50 [file] [log] [blame]
<!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>Expected in 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" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="sidebar-items.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 trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../serde/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../serde/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Expected</a></h2><div class="sidebar-elems"><section><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.fmt">fmt</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-Expected-for-%26%27a%20str">&amp;&#39;a str</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-Display-for-dyn%20Expected%20+%20%27a">Display</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In serde::de</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Trait <a href="../index.html">serde</a>::<wbr><a href="index.html">de</a>::<wbr><a class="trait" href="#">Expected</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></h1><span class="out-of-band"><a class="srclink" href="../../src/serde/de/mod.rs.html#471-475">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust trait"><code>pub trait Expected {
fn <a href="#tymethod.fmt" class="fnname">fmt</a>(&amp;self, formatter: &amp;mut Formatter&lt;'_&gt;) -&gt; Result;
}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><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="example-wrap edition"><div class='tooltip' data-edition="2018"></div><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>visit_bool&lt;E&gt;(<span class="self">self</span>, v: bool) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>::Value, E&gt;
<span class="kw">where
</span>E: de::Error,
{
<span class="prelude-val">Err</span>(de::Error::invalid_type(Unexpected::Bool(v), <span class="kw-2">&amp;</span><span class="self">self</span>))
}</code></pre></div>
<p>Outside of a <code>Visitor</code>, <code>&amp;&quot;...&quot;</code> can be used.</p>
<div class="example-wrap edition"><div class='tooltip' data-edition="2018"></div><pre class="rust rust-example-rendered"><code><span class="kw">return </span><span class="prelude-val">Err</span>(de::Error::invalid_type(Unexpected::Bool(v), <span class="kw-2">&amp;</span><span class="string">&quot;a negative integer&quot;</span>));</code></pre></div>
</div></details><h2 id="required-methods" class="small-section-header">Required Methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.fmt" class="method has-srclink"><a class="srclink rightside" href="../../src/serde/de/mod.rs.html#474">source</a><h4 class="code-header">fn <a href="#tymethod.fmt" class="fnname">fmt</a>(&amp;self, formatter: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></summary><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></details></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Display-for-dyn%20Expected%20+%20%27a" class="impl has-srclink"><a class="srclink rightside" href="../../src/serde/de/mod.rs.html#492-496">source</a><a href="#impl-Display-for-dyn%20Expected%20+%20%27a" class="anchor"></a><h3 class="code-header">impl&lt;'a&gt; Display for dyn <a class="trait" href="trait.Expected.html" title="trait serde::de::Expected">Expected</a> + 'a</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/serde/de/mod.rs.html#493-495">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&amp;self, formatter: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Expected-for-%26%27a%20str" class="impl has-srclink"><a class="srclink rightside" href="../../src/serde/de/mod.rs.html#486-490">source</a><a href="#impl-Expected-for-%26%27a%20str" class="anchor"></a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.Expected.html" title="trait serde::de::Expected">Expected</a> for &amp;'a str</h3></section></summary><div class="impl-items"><section id="method.fmt-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/serde/de/mod.rs.html#487-489">source</a><a href="#method.fmt-1" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.fmt" class="fnname">fmt</a>(&amp;self, formatter: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></div></details><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div id="implementors-list"><section id="impl-Expected-for-T" class="impl has-srclink"><a class="srclink rightside" href="../../src/serde/de/mod.rs.html#477-484">source</a><a href="#impl-Expected-for-T" class="anchor"></a><h3 class="code-header">impl&lt;'de, T&gt; <a class="trait" href="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="trait.Visitor.html" title="trait serde::de::Visitor">Visitor</a>&lt;'de&gt;,</span></h3></section></div><script src="../../implementors/serde/de/trait.Expected.js" data-ignore-extern-crates="core" async></script></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.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>