Files
mercator_service/nom/lib/std/slice/index.html

106 lines
17 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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 `slice` mod in crate `nom`."><meta name="keywords" content="rust, rustlang, rust-lang, slice"><title>nom::lib::std::slice - 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">&#9776;</div><a href='../../../../nom/index.html'><div class='logo-container'><img src='../../../../rust-logo.png' alt='logo'></div></a><p class='location'>Module slice</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'><a href='../../../index.html'>nom</a>::<wbr><a href='../../index.html'>lib</a>::<wbr><a href='../index.html'>std</a></p><script>window.sidebarCurrent = {name: 'slice', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></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"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled 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 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='https://doc.rust-lang.org/nightly/src/alloc/lib.rs.html#158' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../../index.html'>nom</a>::<wbr><a href='../../index.html'>lib</a>::<wbr><a href='../index.html'>std</a>::<wbr><a class="mod" href=''>slice</a></span></h1><div class='docblock'><p>A dynamically-sized view into a contiguous sequence, <code>[T]</code>.</p>
<p><em><a href="../../std/primitive.slice.html">See also the slice primitive type</a>.</em></p>
<p>Slices are a view into a block of memory represented as a pointer and a
length.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="comment">// slicing a Vec</span>
<span class="kw">let</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
<span class="kw">let</span> <span class="ident">int_slice</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="ident">vec</span>[..];
<span class="comment">// coercing an array to a slice</span>
<span class="kw">let</span> <span class="ident">str_slice</span>: <span class="kw-2">&amp;</span>[<span class="kw-2">&amp;</span><span class="ident">str</span>] <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="string">&quot;one&quot;</span>, <span class="string">&quot;two&quot;</span>, <span class="string">&quot;three&quot;</span>];</pre></div>
<p>Slices are either mutable or shared. The shared slice type is <code>&amp;[T]</code>,
while the mutable slice type is <code>&amp;mut [T]</code>, where <code>T</code> represents the element
type. For example, you can mutate the block of memory that a mutable slice
points to:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">mut</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
<span class="ident">x</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">7</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">x</span>, <span class="kw-2">&amp;</span>[<span class="number">1</span>, <span class="number">7</span>, <span class="number">3</span>]);</pre></div>
<p>Here are some of the things this module contains:</p>
<h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
<p>There are several structs that are useful for slices, such as <a href="struct.Iter.html"><code>Iter</code></a>, which
represents iteration over a slice.</p>
<h2 id="trait-implementations" class="section-header"><a href="#trait-implementations">Trait Implementations</a></h2>
<p>There are several implementations of common traits for slices. Some examples
include:</p>
<ul>
<li><a href="../../std/clone/trait.Clone.html"><code>Clone</code></a></li>
<li><a href="../../std/cmp/trait.Eq.html"><code>Eq</code></a>, <a href="../../std/cmp/trait.Ord.html"><code>Ord</code></a> - for slices whose element type are <a href="../../std/cmp/trait.Eq.html"><code>Eq</code></a> or <a href="../../std/cmp/trait.Ord.html"><code>Ord</code></a>.</li>
<li><a href="../../std/hash/trait.Hash.html"><code>Hash</code></a> - for slices whose element type is <a href="../../std/hash/trait.Hash.html"><code>Hash</code></a>.</li>
</ul>
<h2 id="iteration" class="section-header"><a href="#iteration">Iteration</a></h2>
<p>The slices implement <code>IntoIterator</code>. The iterator yields references to the
slice elements.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">numbers</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>];
<span class="kw">for</span> <span class="ident">n</span> <span class="kw">in</span> <span class="ident">numbers</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{} is a number!&quot;</span>, <span class="ident">n</span>);
}</pre></div>
<p>The mutable slice yields mutable references to the elements:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">scores</span> <span class="op">=</span> [<span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>];
<span class="kw">for</span> <span class="ident">score</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">scores</span>[..] {
<span class="kw-2">*</span><span class="ident">score</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
}</pre></div>
<p>This iterator yields mutable references to the slice's elements, so while
the element type of the slice is <code>i32</code>, the element type of the iterator is
<code>&amp;mut i32</code>.</p>
<ul>
<li><a href="../../std/primitive.slice.html#method.iter"><code>.iter</code></a> and <a href="../../std/primitive.slice.html#method.iter_mut"><code>.iter_mut</code></a> are the explicit methods to return the default
iterators.</li>
<li>Further methods that return iterators are <a href="../../std/primitive.slice.html#method.split"><code>.split</code></a>, <a href="../../std/primitive.slice.html#method.splitn"><code>.splitn</code></a>,
<a href="../../std/primitive.slice.html#method.chunks"><code>.chunks</code></a>, <a href="../../std/primitive.slice.html#method.windows"><code>.windows</code></a> and more.</li>
</ul>
</div><h2 id='structs-1' class='section-header'><a href="#structs-1">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.Chunks.html" title='nom::lib::std::slice::Chunks struct'>Chunks</a></td><td class='docblock-short'><p>An iterator over a slice in (non-overlapping) chunks (<code>chunk_size</code> elements at a
time), starting at the beginning of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.ChunksExact.html" title='nom::lib::std::slice::ChunksExact struct'>ChunksExact</a></td><td class='docblock-short'><p>An iterator over a slice in (non-overlapping) chunks (<code>chunk_size</code> elements at a
time), starting at the beginning of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.ChunksExactMut.html" title='nom::lib::std::slice::ChunksExactMut struct'>ChunksExactMut</a></td><td class='docblock-short'><p>An iterator over a slice in (non-overlapping) mutable chunks (<code>chunk_size</code>
elements at a time), starting at the beginning of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.ChunksMut.html" title='nom::lib::std::slice::ChunksMut struct'>ChunksMut</a></td><td class='docblock-short'><p>An iterator over a slice in (non-overlapping) mutable chunks (<code>chunk_size</code>
elements at a time), starting at the beginning of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Iter.html" title='nom::lib::std::slice::Iter struct'>Iter</a></td><td class='docblock-short'><p>Immutable slice iterator</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.IterMut.html" title='nom::lib::std::slice::IterMut struct'>IterMut</a></td><td class='docblock-short'><p>Mutable slice iterator.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.RChunks.html" title='nom::lib::std::slice::RChunks struct'>RChunks</a></td><td class='docblock-short'><p>An iterator over a slice in (non-overlapping) chunks (<code>chunk_size</code> elements at a
time), starting at the end of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.RChunksExact.html" title='nom::lib::std::slice::RChunksExact struct'>RChunksExact</a></td><td class='docblock-short'><p>An iterator over a slice in (non-overlapping) chunks (<code>chunk_size</code> elements at a
time), starting at the end of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.RChunksExactMut.html" title='nom::lib::std::slice::RChunksExactMut struct'>RChunksExactMut</a></td><td class='docblock-short'><p>An iterator over a slice in (non-overlapping) mutable chunks (<code>chunk_size</code>
elements at a time), starting at the end of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.RChunksMut.html" title='nom::lib::std::slice::RChunksMut struct'>RChunksMut</a></td><td class='docblock-short'><p>An iterator over a slice in (non-overlapping) mutable chunks (<code>chunk_size</code>
elements at a time), starting at the end of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.RSplit.html" title='nom::lib::std::slice::RSplit struct'>RSplit</a></td><td class='docblock-short'><p>An iterator over subslices separated by elements that match a predicate
function, starting from the end of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.RSplitMut.html" title='nom::lib::std::slice::RSplitMut struct'>RSplitMut</a></td><td class='docblock-short'><p>An iterator over the subslices of the vector which are separated
by elements that match <code>pred</code>, starting from the end of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.RSplitN.html" title='nom::lib::std::slice::RSplitN struct'>RSplitN</a></td><td class='docblock-short'><p>An iterator over subslices separated by elements that match a
predicate function, limited to a given number of splits, starting
from the end of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.RSplitNMut.html" title='nom::lib::std::slice::RSplitNMut struct'>RSplitNMut</a></td><td class='docblock-short'><p>An iterator over subslices separated by elements that match a
predicate function, limited to a given number of splits, starting
from the end of the slice.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Split.html" title='nom::lib::std::slice::Split struct'>Split</a></td><td class='docblock-short'><p>An iterator over subslices separated by elements that match a predicate
function.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.SplitMut.html" title='nom::lib::std::slice::SplitMut struct'>SplitMut</a></td><td class='docblock-short'><p>An iterator over the mutable subslices of the vector which are separated
by elements that match <code>pred</code>.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.SplitN.html" title='nom::lib::std::slice::SplitN struct'>SplitN</a></td><td class='docblock-short'><p>An iterator over subslices separated by elements that match a predicate
function, limited to a given number of splits.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.SplitNMut.html" title='nom::lib::std::slice::SplitNMut struct'>SplitNMut</a></td><td class='docblock-short'><p>An iterator over subslices separated by elements that match a predicate
function, limited to a given number of splits.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Windows.html" title='nom::lib::std::slice::Windows struct'>Windows</a></td><td class='docblock-short'><p>An iterator over overlapping subslices of length <code>size</code>.</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.SliceIndex.html" title='nom::lib::std::slice::SliceIndex trait'>SliceIndex</a></td><td class='docblock-short'><p>A helper trait used for indexing operations.</p>
</td></tr><tr class='unstable module-item'><td><a class="trait" href="trait.Concat.html" title='nom::lib::std::slice::Concat trait'>Concat</a></td><td class='docblock-short'><span class="stab unstable">Experimental</span><p>Helper trait for <a href="../../std/primitive.slice.html#method.concat"><code>[T]::concat</code></a>.</p>
</td></tr><tr class='unstable module-item'><td><a class="trait" href="trait.Join.html" title='nom::lib::std::slice::Join trait'>Join</a></td><td class='docblock-short'><span class="stab unstable">Experimental</span><p>Helper trait for <a href="../../std/primitive.slice.html#method.join"><code>[T]::join</code></a></p>
</td></tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
<table><tr class='module-item'><td><a class="fn" href="fn.from_mut.html" title='nom::lib::std::slice::from_mut fn'>from_mut</a></td><td class='docblock-short'><p>Converts a reference to T into a slice of length 1 (without copying).</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.from_raw_parts.html" title='nom::lib::std::slice::from_raw_parts fn'>from_raw_parts</a><a title='unsafe function' href='#'><sup></sup></a></td><td class='docblock-short'><p>Forms a slice from a pointer and a length.</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.from_raw_parts_mut.html" title='nom::lib::std::slice::from_raw_parts_mut fn'>from_raw_parts_mut</a><a title='unsafe function' href='#'><sup></sup></a></td><td class='docblock-short'><p>Performs the same functionality as <a href="../../std/slice/fn.from_raw_parts.html"><code>from_raw_parts</code></a>, except that a
mutable slice is returned.</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.from_ref.html" title='nom::lib::std::slice::from_ref fn'>from_ref</a></td><td class='docblock-short'><p>Converts a reference to T into a slice of length 1 (without copying).</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../../../../";window.currentCrate = "nom";</script><script src="../../../../aliases.js"></script><script src="../../../../main.js"></script><script defer src="../../../../search-index.js"></script></body></html>