Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 564935689ab5527f955e5449ded02799 > files > 664

rust-doc-1.19.0-1.mga6.armv7hl.rpm

<!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 `Utf8Error` struct in crate `collections`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, Utf8Error">

    <title>collections::str::Utf8Error - 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">
    

    <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico">
    
</head>
<body class="rustdoc struct">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky
        things.
    </div>
    <![endif]-->

    

    <nav class="sidebar">
        <a href='../../collections/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a>
        <p class='location'>Struct Utf8Error</p><div class="block items"><ul><li><a href="#methods">Methods</a></li><li><a href="#implementations">Trait Implementations</a></li></ul></div><p class='location'><a href='../index.html'>collections</a>::<wbr><a href='index.html'>str</a></p><script>window.sidebarCurrent = {name: 'Utf8Error', ty: 'struct', 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'>Struct <a href='../index.html'>collections</a>::<wbr><a href='index.html'>str</a>::<wbr><a class="struct" href=''>Utf8Error</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><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/core/str/mod.rs.html#167-170' title='goto source code'>[src]</a></span></h1>
<pre class='rust struct'>pub struct Utf8Error { /* fields omitted */ }</pre><div class='docblock'><p>Errors which can occur when attempting to interpret a sequence of <a href="../../std/primitive.u8.html"><code>u8</code></a>
as a string.</p>

<p>As such, the <code>from_utf8</code> family of functions and methods for both <a href="../../std/string/struct.String.html#method.from_utf8"><code>String</code></a>s
and <a href="../../std/str/fn.from_utf8.html"><code>&amp;str</code></a>s make use of this error, for example.</p>
</div><h2 id='methods'>Methods</h2><h3 class='impl'><span class='in-band'><code>impl <a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/str/mod.rs.html#172-214' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.valid_up_to' class="method"><span id='valid_up_to.v' class='invisible'><code>fn <a href='#method.valid_up_to' class='fnname'>valid_up_to</a>(&amp;self) -&gt; usize</code><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div></span></h4>
<div class='docblock'><p>Returns the index in the given string up to which valid UTF-8 was
verified.</p>

<p>It is the maximum index such that <code>from_utf8(&amp;input[..index])</code>
would return <code>Ok(_)</code>.</p>

<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
<p>Basic usage:</p>

<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">str</span>;

<span class="comment">// some invalid bytes, in a vector</span>
<span class="kw">let</span> <span class="ident">sparkle_heart</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">159</span>, <span class="number">146</span>, <span class="number">150</span>];

<span class="comment">// std::str::from_utf8 returns a Utf8Error</span>
<span class="kw">let</span> <span class="ident">error</span> <span class="op">=</span> <span class="ident">str</span>::<span class="ident">from_utf8</span>(<span class="kw-2">&amp;</span><span class="ident">sparkle_heart</span>).<span class="ident">unwrap_err</span>();

<span class="comment">// the second byte is invalid here</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">1</span>, <span class="ident">error</span>.<span class="ident">valid_up_to</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Astr%3B%0A%0A%2F%2F%20some%20invalid%20bytes%2C%20in%20a%20vector%0Alet%20sparkle_heart%20%3D%20vec!%5B0%2C%20159%2C%20146%2C%20150%5D%3B%0A%0A%2F%2F%20std%3A%3Astr%3A%3Afrom_utf8%20returns%20a%20Utf8Error%0Alet%20error%20%3D%20str%3A%3Afrom_utf8(%26sparkle_heart).unwrap_err()%3B%0A%0A%2F%2F%20the%20second%20byte%20is%20invalid%20here%0Aassert_eq!(1%2C%20error.valid_up_to())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.error_len' class="method"><span id='error_len.v' class='invisible'><code>fn <a href='#method.error_len' class='fnname'>error_len</a>(&amp;self) -&gt; <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;usize&gt;</code></span></h4>
<div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>utf8_error_error_len </code><a href="https://github.com/rust-lang/rust/issues/40494">#40494</a>)</summary><p>new</p>
</details></div></div><div class='docblock'><p>Provide more information about the failure:</p>

<ul>
<li><p><code>None</code>: the end of the input was reached unexpectedly.
<code>self.valid_up_to()</code> is 1 to 3 bytes from the end of the input.
If a byte stream (such as a file or a network socket) is being decoded incrementally,
this could be a valid <code>char</code> whose UTF-8 byte sequence is spanning multiple chunks.</p></li>
<li><p><code>Some(len)</code>: an unexpected byte was encountered.
The length provided is that of the invalid byte sequence
that starts at the index given by <code>valid_up_to()</code>.
Decoding should resume after that sequence
(after inserting a U+FFFD REPLACEMENT CHARACTER) in case of lossy decoding.</p></li>
</ul>
</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/str/mod.rs.html#165' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><code>fn <a href='../../core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&amp;self) -&gt; <a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a></code></span></h4>
<div class='docblock'><p>Returns a copy of the value. <a href="../../core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
</div><h4 id='method.clone_from' class="method"><span id='clone_from.v' class='invisible'><code>fn <a href='../../core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&amp;mut self, source: &amp;Self)</code></span></h4>
<div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="../../core/clone/trait.Clone.html#method.clone_from">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../collections/fmt/trait.Display.html" title="trait collections::fmt::Display">Display</a> for <a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/str/mod.rs.html#391-400' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='../../collections/fmt/trait.Display.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="../../collections/fmt/struct.Formatter.html" title="struct collections::fmt::Formatter">Formatter</a>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(), <a class="struct" href="../../collections/fmt/struct.Error.html" title="struct collections::fmt::Error">Error</a>&gt;</code></span></h4>
<div class='docblock'><p>Formats the value using the given formatter. <a href="../../collections/fmt/trait.Display.html#tymethod.fmt">Read more</a></p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>&lt;<a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a>&gt; for <a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/str/mod.rs.html#165' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq' class="method"><span id='eq.v' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a>) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne' class="method"><span id='ne.v' class='invisible'><code>fn <a href='../../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a>) -&gt; bool</code></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../collections/fmt/trait.Debug.html" title="trait collections::fmt::Debug">Debug</a> for <a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/str/mod.rs.html#165' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.fmt-1' class="method"><span id='fmt.v-1' class='invisible'><code>fn <a href='../../collections/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, __arg_0: &amp;mut <a class="struct" href="../../collections/fmt/struct.Formatter.html" title="struct collections::fmt::Formatter">Formatter</a>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(), <a class="struct" href="../../collections/fmt/struct.Error.html" title="struct collections::fmt::Error">Error</a>&gt;</code></span></h4>
<div class='docblock'><p>Formats the value using the given formatter.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> for <a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/str/mod.rs.html#165' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="../../core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a> for <a class="struct" href="../../collections/str/struct.Utf8Error.html" title="struct collections::str::Utf8Error">Utf8Error</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/str/mod.rs.html#165' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'></div></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>&larrb;</dt>
                    <dd>Move up in search results</dd>
                    <dt>&rarrb;</dt>
                    <dd>Move down in search results</dd>
                    <dt>&#9166;</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 = "collections";
    </script>
    <script src="../../main.js"></script>
    <script defer src="../../search-index.js"></script>
</body>
</html>