Files
trussed/generic_array/index.html
T
2023-01-22 17:57:37 +00:00

42 lines
9.2 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="This crate implements a structure that can be used as a generic array type. Core Rust array types `[T; N]` can’t be used generically with respect to `N`, so for example this:"><meta name="keywords" content="rust, rustlang, rust-lang, generic_array"><title>generic_array - 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="../crates.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 mod crate"><!--[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="../generic_array/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="../generic_array/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate generic_array</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.14.6</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#reexports">Re-exports</a></li><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><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></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">generic_array</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/generic_array/lib.rs.html#1-679">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This crate implements a structure that can be used as a generic array type.
Core Rust array types <code>[T; N]</code> can’t be used generically with
respect to <code>N</code>, so for example this:</p>
<div class="example-wrap"><pre class="language-rust{compile_fail}"><code>struct Foo&lt;T, N&gt; {
data: [T; N]
}
</code></pre></div>
<p>won’t work.</p>
<p><strong>generic-array</strong> exports a <code>GenericArray&lt;T,N&gt;</code> type, which lets
the above be implemented as:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>generic_array::{ArrayLength, GenericArray};
<span class="kw">struct </span>Foo&lt;T, N: ArrayLength&lt;T&gt;&gt; {
data: GenericArray&lt;T,N&gt;
}</code></pre></div>
<p>The <code>ArrayLength&lt;T&gt;</code> trait is implemented by default for
<a href="../typenum/uint/index.html">unsigned integer types</a> from
<a href="../typenum/index.html">typenum</a>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>generic_array::typenum::U5;
<span class="kw">struct </span>Foo&lt;N: ArrayLength&lt;i32&gt;&gt; {
data: GenericArray&lt;i32, N&gt;
}
<span class="kw">let </span>foo = Foo::&lt;U5&gt;{data: GenericArray::default()};</code></pre></div>
<p>For example, <code>GenericArray&lt;T, U5&gt;</code> would work almost like <code>[T; 5]</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>generic_array::typenum::U5;
<span class="kw">struct </span>Foo&lt;T, N: ArrayLength&lt;T&gt;&gt; {
data: GenericArray&lt;T, N&gt;
}
<span class="kw">let </span>foo = Foo::&lt;i32, U5&gt;{data: GenericArray::default()};</code></pre></div>
<p>For ease of use, an <code>arr!</code> macro is provided - example below:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>array = <span class="macro">arr!</span>[u32; <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
<span class="macro">assert_eq!</span>(array[<span class="number">2</span>], <span class="number">3</span>);</code></pre></div>
</div></details><h2 id="reexports" class="small-section-header"><a href="#reexports">Re-exports</a></h2><div class="item-table"><div class="item-row"><div class="item-left"><code>pub extern crate <a class="mod" href="../typenum/index.html" title="mod typenum">typenum</a>;</code></div></div><div class="item-row"><div class="item-left import-item" id="reexport.GenericArrayIter"><code>pub use self::iter::<a class="struct" href="iter/struct.GenericArrayIter.html" title="struct generic_array::iter::GenericArrayIter">GenericArrayIter</a>;</code></div></div></div><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="arr/index.html" title="generic_array::arr mod">arr</a></div><div class="item-right docblock-short">Implementation for <code>arr!</code> macro.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="functional/index.html" title="generic_array::functional mod">functional</a></div><div class="item-right docblock-short">Functional programming with generic sequences</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="iter/index.html" title="generic_array::iter mod">iter</a></div><div class="item-right docblock-short"><code>GenericArray</code> iterator implementation.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="sequence/index.html" title="generic_array::sequence mod">sequence</a></div><div class="item-right docblock-short">Useful traits for manipulating sequences of data stored in <code>GenericArray</code>s</div></div></div><h2 id="macros" class="small-section-header"><a href="#macros">Macros</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.arr.html" title="generic_array::arr macro">arr</a></div><div class="item-right docblock-short">Macro allowing for easy generation of Generic Arrays.
Example: <code>let test = arr![u32; 1, 2, 3];</code></div></div></div><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.GenericArray.html" title="generic_array::GenericArray struct">GenericArray</a></div><div class="item-right docblock-short">Struct representing a generic array - <code>GenericArray&lt;T, N&gt;</code> works like [T; N]</div></div></div><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.ArrayLength.html" title="generic_array::ArrayLength trait">ArrayLength</a></div><div class="item-right docblock-short">Trait making <code>GenericArray</code> work, marking types to be used as length of an array</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="generic_array" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.1 (90743e729 2023-01-10)" ></div></body></html>