oxipng/doc/bitflags/__core/slice/index.html
2016-05-04 10:41:29 -04:00

293 lines
No EOL
15 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 `bitflags`.">
<meta name="keywords" content="rust, rustlang, rust-lang, slice">
<title>bitflags::__core::slice - Rust</title>
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../../main.css">
</head>
<body class="rustdoc">
<!--[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'><a href='../../index.html'>bitflags</a>::<wbr><a href='../index.html'>__core</a></p><script>window.sidebarCurrent = {name: 'slice', 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 mod">
<h1 class='fqn'><span class='in-band'>Module <a href='../../index.html'>bitflags</a>::<wbr><a href='../index.html'>__core</a>::<wbr><a class='mod' href=''>slice</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'>&#x2212;</span>]
</a>
</span><a id='src-2962' class='srclink' href='https://doc.rust-lang.org/nightly/collections/slice/index.html?gotosrc=2962' title='goto source code'>[src]</a></span></h1>
<div class='docblock'><p>A dynamically-sized view into a contiguous sequence, <code>[T]</code>.</p>
<p>Slices are a view into a block of memory represented as a pointer and a
length.</p>
<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>
<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>
<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>
<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 <code>Iter</code>, 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><code>Clone</code></li>
<li><code>Eq</code>, <code>Ord</code> - for slices whose element type are <code>Eq</code> or <code>Ord</code>.</li>
<li><code>Hash</code> - for slices whose element type is <code>Hash</code></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>
<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>
<p>The mutable slice yields mutable references to the elements:</p>
<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='op'>*</span><span class='ident'>score</span> <span class='op'>+=</span> <span class='number'>1</span>;
}</pre>
<p>This iterator yields mutable references to the slice&#39;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><code>.iter()</code> and <code>.iter_mut()</code> are the explicit methods to return the default
iterators.</li>
<li>Further methods that return iterators are <code>.split()</code>, <code>.splitn()</code>,
<code>.chunks()</code>, <code>.windows()</code> and more.</li>
</ul>
<p><em><a href="../../std/primitive.slice.html">See also the slice primitive type</a>.</em></p>
</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='bitflags::__core::slice::Chunks'>Chunks</a></td>
<td class='docblock short'>
<p>An iterator over a slice in (non-overlapping) chunks (<code>size</code> elements at a
time).</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class='struct' href='struct.ChunksMut.html'
title='bitflags::__core::slice::ChunksMut'>ChunksMut</a></td>
<td class='docblock short'>
<p>An iterator over a slice in (non-overlapping) mutable chunks (<code>size</code>
elements at a time). When the slice len is not evenly divided by the chunk
size, the last slice of the iteration will be the remainder.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class='struct' href='struct.Iter.html'
title='bitflags::__core::slice::Iter'>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='bitflags::__core::slice::IterMut'>IterMut</a></td>
<td class='docblock short'>
<p>Mutable slice iterator.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class='struct' href='struct.RSplitN.html'
title='bitflags::__core::slice::RSplitN'>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='bitflags::__core::slice::RSplitNMut'>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='bitflags::__core::slice::Split'>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='bitflags::__core::slice::SplitMut'>SplitMut</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>.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class='struct' href='struct.SplitN.html'
title='bitflags::__core::slice::SplitN'>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='bitflags::__core::slice::SplitNMut'>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='bitflags::__core::slice::Windows'>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='unstable module-item'>
<td><a class='trait' href='trait.SliceConcatExt.html'
title='bitflags::__core::slice::SliceConcatExt'>SliceConcatExt</a></td>
<td class='docblock short'>
[<em class='stab unstable'>Unstable</em>] <p>An extension trait for concatenating slices</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_raw_parts.html'
title='bitflags::__core::slice::from_raw_parts'>from_raw_parts</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='bitflags::__core::slice::from_raw_parts_mut'>from_raw_parts_mut</a></td>
<td class='docblock short'>
<p>Performs the same functionality as <code>from_raw_parts</code>, except that a mutable
slice is returned.</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>&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>
</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 = "bitflags";
window.playgroundUrl = "";
</script>
<script src="../../../jquery.js"></script>
<script src="../../../main.js"></script>
<script defer src="../../../search-index.js"></script>
</body>
</html>