Files
phy/rawpointer/index.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

46 lines
6.8 KiB
HTML

<!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="Rawpointer adds extra utility methods to raw pointers `*const T`, `*mut T` and `NonNull&#60;T&#62;`."><title>rawpointer - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="rawpointer" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../rawpointer/index.html">rawpointer</a><span class="version">0.2.1</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#safety" title="Safety">Safety</a></li><li><a href="#rust-version" title="Rust Version">Rust Version</a></li></ul><h3><a href="#traits">Crate Items</a></h3><ul class="block"><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>rawpointer</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/rawpointer/lib.rs.html#8-246">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Rawpointer adds extra utility methods to raw pointers <code>*const T</code>, <code>*mut T</code>
and <code>NonNull&lt;T&gt;</code>.</p>
<p>Features include:</p>
<ul>
<li>
<p>Strided offsets - <a href="trait.PointerExt.html#method.stride_offset" title="method rawpointer::PointerExt::stride_offset"><code>.stride_offset(stride, index)</code></a> make it easy to compute
pointer offsets where the index is unsigned and the stride is signed.</p>
</li>
<li>
<p>Offsetting methods in general for <code>NonNull</code>, since it does not have these
from libcore</p>
</li>
<li>
<p>Post- and preincrement and post- and predecrement methods</p>
<ul>
<li>For <code>p++</code> use <a href="trait.PointerExt.html#method.post_inc" title="method rawpointer::PointerExt::post_inc"><code>p.post_inc()</code></a>.</li>
<li>For <code>++p</code> use <a href="trait.PointerExt.html#method.pre_inc" title="method rawpointer::PointerExt::pre_inc"><code>p.pre_inc()</code></a>.</li>
<li>For <code>p--</code> use <a href="trait.PointerExt.html#method.post_dec" title="method rawpointer::PointerExt::post_dec"><code>p.post_dec()</code></a>.</li>
<li>For <code>--p</code> use <a href="trait.PointerExt.html#method.pre_dec" title="method rawpointer::PointerExt::pre_dec"><code>p.pre_dec()</code></a>.</li>
</ul>
</li>
</ul>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rawpointer::PointerExt;
<span class="kw">unsafe </span>{
<span class="comment">// In this example:
// Use .post_inc() to iterate and overwrite the first four
// elements of the array.
</span><span class="kw">let </span><span class="kw-2">mut </span>xs = [<span class="number">0</span>; <span class="number">16</span>];
<span class="kw">let </span><span class="kw-2">mut </span>ptr = xs.as_mut_ptr();
<span class="kw">let </span>end = ptr.offset(<span class="number">4</span>);
<span class="kw">let </span><span class="kw-2">mut </span>i = <span class="number">0</span>;
<span class="kw">while </span>ptr != end {
<span class="kw-2">*</span>ptr.post_inc() = i;
i += <span class="number">1</span>;
}
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>xs[..<span class="number">8</span>], <span class="kw-2">&amp;</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>]);
}</code></pre></div>
<h3 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h3>
<p>See the Rust <a href="https://doc.rust-lang.org/1.84.0/core/ptr/index.html" title="mod core::ptr">core::ptr</a> documentation for more information.</p>
<h3 id="rust-version"><a class="doc-anchor" href="#rust-version">§</a>Rust Version</h3>
<p>This version of the crate requires Rust 1.26 or later</p>
</div></details><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.PointerExt.html" title="trait rawpointer::PointerExt">Pointer<wbr>Ext</a></div><div class="desc docblock-short">Extension methods for raw pointers</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.ptrdistance.html" title="fn rawpointer::ptrdistance">ptrdistance</a></div><div class="desc docblock-short">Return the number of elements of <code>T</code> from <code>start</code> to <code>end</code>.<br>
Return the arithmetic difference if <code>T</code> is zero size.</div></li></ul></section></div></main></body></html>