<!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="Extra indexing methods for array views"><meta name="keywords" content="rust, rustlang, rust-lang, IndexLonger"><title>IndexLonger in ndarray - 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="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></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="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../ndarray/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><h2 class="location">Trait IndexLonger</h2><div class="sidebar-elems"><div class="block items"><h3 class="sidebar-title"><a href="#associated-types">Associated Types</a></h3><div class="sidebar-links"><a href="#associatedtype.Output">Output</a></div><h3 class="sidebar-title"><a href="#required-methods">Required Methods</a></h3><div class="sidebar-links"><a href="#tymethod.get">get</a><a href="#tymethod.index">index</a><a href="#tymethod.uget">uget</a></div><h3 class="sidebar-title"><a href="#implementors">Implementors</a></h3></div><h2 class="location">Other items in<br><a href="index.html">ndarray</a></h2><div id="sidebar-vars" data-name="IndexLonger" data-ty="trait" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img src="../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><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><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../settings.html" title="settings"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Trait <a href="index.html">ndarray</a>::<wbr><a class="trait" href="#">IndexLonger</a><button id="copy-path" onclick="copy_path(this)" title="copy path"><img src="../clipboard.svg" width="19" height="18" alt="Copy item import" title="Copy item import to clipboard"></button></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">−</span>]</a></span><a class="srclink" href="../src/ndarray/impl_views.rs.html#176-221" title="goto source code">[src]</a></span></h1><div class="docblock type-decl"><pre class="rust trait">pub trait IndexLonger<I> {
type <a href="#associatedtype.Output" class="type">Output</a>;
fn <a href="#tymethod.index" class="fnname">index</a>(self, index: I) -> Self::<a class="type" href="trait.IndexLonger.html#associatedtype.Output" title="type ndarray::IndexLonger::Output">Output</a>;
<div class="item-spacer"></div> fn <a href="#tymethod.get" class="fnname">get</a>(self, index: I) -> <a class="enum" href="https://doc.rust-lang.org/1.54.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="trait.IndexLonger.html#associatedtype.Output" title="type ndarray::IndexLonger::Output">Output</a>>;
<div class="item-spacer"></div> unsafe fn <a href="#tymethod.uget" class="fnname">uget</a>(self, index: I) -> Self::<a class="type" href="trait.IndexLonger.html#associatedtype.Output" title="type ndarray::IndexLonger::Output">Output</a>;
}</pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extra indexing methods for array views</p>
<p>These methods are very similar to regular indexing or calling of the
<code>get</code>/<code>get_mut</code> methods that we can use on any array or array view. The
difference here is in the length of lifetime in the resulting reference.</p>
<p><strong>Note</strong> that the <code>ArrayView</code> (read-only) and <code>ArrayViewMut</code> (read-write) differ
in how they are allowed implement this trait – <code>ArrayView</code>’s implementation
is usual. If you put in a <code>ArrayView<'a, T, D></code> here, you get references
<code>&'a T</code> out.</p>
<p>For <code>ArrayViewMut</code> to obey the borrowing rules we have to consume the
view if we call any of these methods. (The equivalent of reborrow is
<code>.view_mut()</code> for read-write array views, but if you can use that,
then the regular indexing / <code>get_mut</code> should suffice, too.)</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">ndarray::IndexLonger</span>;
<span class="kw">use</span> <span class="ident">ndarray::ArrayView</span>;
<span class="kw">let</span> <span class="ident">data</span> <span class="op">=</span> [<span class="number">0.</span>; <span class="number">256</span>];
<span class="kw">let</span> <span class="ident">long_life_ref</span> <span class="op">=</span> {
<span class="comment">// make a 16 × 16 array view</span>
<span class="kw">let</span> <span class="ident">view</span> <span class="op">=</span> <span class="ident">ArrayView::from</span>(<span class="kw-2">&</span><span class="ident">data</span>[..]).<span class="ident">into_shape</span>((<span class="number">16</span>, <span class="number">16</span>)).<span class="ident">unwrap</span>();
<span class="comment">// index the view and with `IndexLonger`.</span>
<span class="comment">// Note here that we get a reference with a life that is derived from</span>
<span class="comment">// `data`, the base data, instead of being derived from the view</span>
<span class="ident">IndexLonger::index</span>(<span class="kw-2">&</span><span class="ident">view</span>, [<span class="number">0</span>, <span class="number">1</span>])
};
<span class="comment">// view goes out of scope</span>
<span class="macro">assert_eq!</span>(<span class="ident">long_life_ref</span>, <span class="kw-2">&</span><span class="number">0.</span>);
</pre></div>
</div></details><h2 id="associated-types" class="small-section-header">Associated Types<a href="#associated-types" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle" open><summary><div id="associatedtype.Output" class="method has-srclink"><h4 class="code-header">type <a href="#associatedtype.Output" class="type">Output</a></h4><a class="srclink" href="../src/ndarray/impl_views.rs.html#179" title="goto source code">[src]</a></div></summary><div class="docblock"><p>The type of the reference to the element that is produced, including
its lifetime.</p>
</div></details></div><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" open><summary><div id="tymethod.index" class="method has-srclink"><h4 class="code-header">fn <a href="#tymethod.index" class="fnname">index</a>(self, index: I) -> Self::<a class="type" href="trait.IndexLonger.html#associatedtype.Output" title="type ndarray::IndexLonger::Output">Output</a></h4><a class="srclink" href="../src/ndarray/impl_views.rs.html#192" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Get a reference of a element through the view.</p>
<p>This method is like <code>Index::index</code> but with a longer lifetime (matching
the array view); which we can only do for the array view and not in the
<code>Index</code> trait.</p>
<p>See also <a href="struct.ArrayBase.html#method.get">the <code>get</code> method</a> which works for all arrays and array
views.</p>
<p><strong>Panics</strong> if index is out of bounds.</p>
</div></details><details class="rustdoc-toggle" open><summary><div id="tymethod.get" class="method has-srclink"><h4 class="code-header">fn <a href="#tymethod.get" class="fnname">get</a>(self, index: I) -> <a class="enum" href="https://doc.rust-lang.org/1.54.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="trait.IndexLonger.html#associatedtype.Output" title="type ndarray::IndexLonger::Output">Output</a>></h4><a class="srclink" href="../src/ndarray/impl_views.rs.html#207" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Get a reference of a element through the view.</p>
<p>This method is like <code>ArrayBase::get</code> but with a longer lifetime (matching
the array view); which we can only do for the array view and not in the
<code>Index</code> trait.</p>
<p>See also <a href="struct.ArrayBase.html#method.get">the <code>get</code> method</a> (and <a href="struct.ArrayBase.html#method.get_mut"><code>get_mut</code></a>) which works for all arrays and array
views.</p>
<p><strong>Panics</strong> if index is out of bounds.</p>
</div></details><details class="rustdoc-toggle" open><summary><div id="tymethod.uget" class="method has-srclink"><h4 class="code-header">unsafe fn <a href="#tymethod.uget" class="fnname">uget</a>(self, index: I) -> Self::<a class="type" href="trait.IndexLonger.html#associatedtype.Output" title="type ndarray::IndexLonger::Output">Output</a></h4><a class="srclink" href="../src/ndarray/impl_views.rs.html#220" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Get a reference of a element through the view without boundary check</p>
<p>This method is like <code>elem</code> with a longer lifetime (matching the array
view); which we can’t do for general arrays.</p>
<p>See also <a href="struct.ArrayBase.html#method.uget">the <code>uget</code> method</a> which works for all arrays and array
views.</p>
<p><strong>Note:</strong> only unchecked for non-debug builds of ndarray.</p>
</div></details></div><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><details class="rustdoc-toggle implementors-toggle"><summary><div id="impl-IndexLonger%3CI%3E" class="impl has-srclink"><h3 class="code-header in-band">impl<'a, 'b, I, A, D> <a class="trait" href="trait.IndexLonger.html" title="trait ndarray::IndexLonger">IndexLonger</a><I> for &'b <a class="type" href="type.ArrayView.html" title="type ndarray::ArrayView">ArrayView</a><'a, A, D> <span class="where fmt-newline">where<br> I: <a class="trait" href="trait.NdIndex.html" title="trait ndarray::NdIndex">NdIndex</a><D>,<br> D: <a class="trait" href="trait.Dimension.html" title="trait ndarray::Dimension">Dimension</a>, </span></h3><a href="#impl-IndexLonger%3CI%3E" class="anchor"></a><a class="srclink" href="../src/ndarray/impl_views.rs.html#223-272" title="goto source code">[src]</a></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.index" class="method trait-impl has-srclink"><h4 class="code-header">fn <a href="#tymethod.index" class="fnname">index</a>(self, index: I) -> <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&'a </a>A</h4><a href="#method.index" class="anchor"></a><a class="srclink" href="../src/ndarray/impl_views.rs.html#241-247" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Get a reference of a element through the view.</p>
<p>This method is like <code>Index::index</code> but with a longer lifetime (matching
the array view); which we can only do for the array view and not in the
<code>Index</code> trait.</p>
<p>See also <a href="struct.ArrayBase.html#method.get">the <code>get</code> method</a> which works for all arrays and array
views.</p>
<p><strong>Panics</strong> if index is out of bounds.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.uget" class="method trait-impl has-srclink"><h4 class="code-header">unsafe fn <a href="#tymethod.uget" class="fnname">uget</a>(self, index: I) -> <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&'a </a>A</h4><a href="#method.uget" class="anchor"></a><a class="srclink" href="../src/ndarray/impl_views.rs.html#267-271" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Get a reference of a element through the view without boundary check</p>
<p>This method is like <code>elem</code> with a longer lifetime (matching the array
view); which we can’t do for general arrays.</p>
<p>See also <a href="struct.ArrayBase.html#method.uget">the <code>uget</code> method</a> which works for all arrays and array
views.</p>
<p><strong>Note:</strong> only unchecked for non-debug builds of ndarray.</p>
</div></details><div id="associatedtype.Output-1" class="type trait-impl has-srclink"><h4 class="code-header">type <a href="#associatedtype.Output" class="type">Output</a> = <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&'a </a>A</h4><a href="#associatedtype.Output-1" class="anchor"></a></div><div id="method.get" class="method trait-impl has-srclink"><h4 class="code-header">fn <a href="#tymethod.get" class="fnname">get</a>(self, index: I) -> <a class="enum" href="https://doc.rust-lang.org/1.54.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&'a </a>A></h4><a href="#method.get" class="anchor"></a><a class="srclink" href="../src/ndarray/impl_views.rs.html#249-254" title="goto source code">[src]</a></div></div></details><details class="rustdoc-toggle implementors-toggle"><summary><div id="impl-IndexLonger%3CI%3E-1" class="impl has-srclink"><h3 class="code-header in-band">impl<'a, I, A, D> <a class="trait" href="trait.IndexLonger.html" title="trait ndarray::IndexLonger">IndexLonger</a><I> for <a class="type" href="type.ArrayViewMut.html" title="type ndarray::ArrayViewMut">ArrayViewMut</a><'a, A, D> <span class="where fmt-newline">where<br> I: <a class="trait" href="trait.NdIndex.html" title="trait ndarray::NdIndex">NdIndex</a><D>,<br> D: <a class="trait" href="trait.Dimension.html" title="trait ndarray::Dimension">Dimension</a>, </span></h3><a href="#impl-IndexLonger%3CI%3E-1" class="anchor"></a><a class="srclink" href="../src/ndarray/impl_views.rs.html#374-433" title="goto source code">[src]</a></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.index-1" class="method trait-impl has-srclink"><h4 class="code-header">fn <a href="#tymethod.index" class="fnname">index</a>(self, index: I) -> <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&'a mut </a>A</h4><a href="#method.index-1" class="anchor"></a><a class="srclink" href="../src/ndarray/impl_views.rs.html#392-400" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Convert a mutable array view to a mutable reference of a element.</p>
<p>This method is like <code>IndexMut::index_mut</code> but with a longer lifetime
(matching the array view); which we can only do for the array view and
not in the <code>Index</code> trait.</p>
<p>See also <a href="struct.ArrayBase.html#method.get_mut">the <code>get_mut</code> method</a> which works for all arrays and array
views.</p>
<p><strong>Panics</strong> if index is out of bounds.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.get-1" class="method trait-impl has-srclink"><h4 class="code-header">fn <a href="#tymethod.get" class="fnname">get</a>(self, index: I) -> <a class="enum" href="https://doc.rust-lang.org/1.54.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&'a mut </a>A></h4><a href="#method.get-1" class="anchor"></a><a class="srclink" href="../src/ndarray/impl_views.rs.html#410-418" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Convert a mutable array view to a mutable reference of a element, with
checked access.</p>
<p>See also <a href="struct.ArrayBase.html#method.get_mut">the <code>get_mut</code> method</a> which works for all arrays and array
views.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.uget-1" class="method trait-impl has-srclink"><h4 class="code-header">unsafe fn <a href="#tymethod.uget" class="fnname">uget</a>(self, index: I) -> <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&'a mut </a>A</h4><a href="#method.uget-1" class="anchor"></a><a class="srclink" href="../src/ndarray/impl_views.rs.html#429-432" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Convert a mutable array view to a mutable reference of a element without
boundary check.</p>
<p>See also <a href="struct.ArrayBase.html#method.uget_mut">the <code>uget_mut</code> method</a> which works for all arrays and array
views.</p>
<p><strong>Note:</strong> only unchecked for non-debug builds of ndarray.</p>
</div></details><div id="associatedtype.Output-2" class="type trait-impl has-srclink"><h4 class="code-header">type <a href="#associatedtype.Output" class="type">Output</a> = <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&'a mut </a>A</h4><a href="#associatedtype.Output-2" class="anchor"></a></div></div></details></div><script type="text/javascript" src="../implementors/ndarray/trait.IndexLonger.js" async></script></section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="ndarray" data-search-index-js="../search-index.js" data-search-js="../search.js"></div><script src="../main.js"></script></body></html>