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

33 lines
16 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="Extension methods for raw pointers"><title>PointerExt in 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="sidebar-items.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 trait"><!--[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"><section id="rustdoc-toc"><h2 class="location"><a href="#">Pointer<wbr>Ext</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.offset" title="offset">offset</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.add" title="add">add</a></li><li><a href="#method.dec" title="dec">dec</a></li><li><a href="#method.inc" title="inc">inc</a></li><li><a href="#method.post_dec" title="post_dec">post_dec</a></li><li><a href="#method.post_inc" title="post_inc">post_inc</a></li><li><a href="#method.pre_dec" title="pre_dec">pre_dec</a></li><li><a href="#method.pre_inc" title="pre_inc">pre_inc</a></li><li><a href="#method.stride_offset" title="stride_offset">stride_offset</a></li><li><a href="#method.sub" title="sub">sub</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-PointerExt-for-*const+T" title="*const T">*const T</a></li><li><a href="#impl-PointerExt-for-*mut+T" title="*mut T">*mut T</a></li><li><a href="#impl-PointerExt-for-NonNull%3CT%3E" title="NonNull&#60;T&#62;">NonNull&#60;T&#62;</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate rawpointer</a></h2></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"><span class="rustdoc-breadcrumbs"><a href="index.html">rawpointer</a></span><h1>Trait <span class="trait">PointerExt</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#74-140">Source</a> </span></div><pre class="rust item-decl"><code>pub trait PointerExt: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a> {
// Required method
unsafe fn <a href="#tymethod.offset" class="fn">offset</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.isize.html">isize</a>) -&gt; Self;
// Provided methods
unsafe fn <a href="#method.add" class="fn">add</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.usize.html">usize</a>) -&gt; Self { ... }
<span class="item-spacer"></span> unsafe fn <a href="#method.sub" class="fn">sub</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.usize.html">usize</a>) -&gt; Self { ... }
<span class="item-spacer"></span> unsafe fn <a href="#method.pre_inc" class="fn">pre_inc</a>(&amp;mut self) -&gt; Self { ... }
<span class="item-spacer"></span> unsafe fn <a href="#method.post_inc" class="fn">post_inc</a>(&amp;mut self) -&gt; Self { ... }
<span class="item-spacer"></span> unsafe fn <a href="#method.pre_dec" class="fn">pre_dec</a>(&amp;mut self) -&gt; Self { ... }
<span class="item-spacer"></span> unsafe fn <a href="#method.post_dec" class="fn">post_dec</a>(&amp;mut self) -&gt; Self { ... }
<span class="item-spacer"></span> unsafe fn <a href="#method.inc" class="fn">inc</a>(&amp;mut self) { ... }
<span class="item-spacer"></span> unsafe fn <a href="#method.dec" class="fn">dec</a>(&amp;mut self) { ... }
<span class="item-spacer"></span> unsafe fn <a href="#method.stride_offset" class="fn">stride_offset</a>(self, s: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.isize.html">isize</a>, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.usize.html">usize</a>) -&gt; Self { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extension methods for raw pointers</p>
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><section id="tymethod.offset" class="method"><a class="src rightside" href="../src/rawpointer/lib.rs.html#75">Source</a><h4 class="code-header">unsafe fn <a href="#tymethod.offset" class="fn">offset</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.isize.html">isize</a>) -&gt; Self</h4></section></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><section id="method.add" class="method"><a class="src rightside" href="../src/rawpointer/lib.rs.html#77-79">Source</a><h4 class="code-header">unsafe fn <a href="#method.add" class="fn">add</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.usize.html">usize</a>) -&gt; Self</h4></section><section id="method.sub" class="method"><a class="src rightside" href="../src/rawpointer/lib.rs.html#81-83">Source</a><h4 class="code-header">unsafe fn <a href="#method.sub" class="fn">sub</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.usize.html">usize</a>) -&gt; Self</h4></section><details class="toggle method-toggle" open><summary><section id="method.pre_inc" class="method"><a class="src rightside" href="../src/rawpointer/lib.rs.html#89-92">Source</a><h4 class="code-header">unsafe fn <a href="#method.pre_inc" class="fn">pre_inc</a>(&amp;mut self) -&gt; Self</h4></section></summary><div class="docblock"><p>Increment the pointer by 1, and return its new value.</p>
<p>Equivalent to the C idiom <code>++ptr</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.post_inc" class="method"><a class="src rightside" href="../src/rawpointer/lib.rs.html#98-102">Source</a><h4 class="code-header">unsafe fn <a href="#method.post_inc" class="fn">post_inc</a>(&amp;mut self) -&gt; Self</h4></section></summary><div class="docblock"><p>Increment the pointer by 1, but return its old value.</p>
<p>Equivalent to the C idiom <code>ptr++</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.pre_dec" class="method"><a class="src rightside" href="../src/rawpointer/lib.rs.html#108-111">Source</a><h4 class="code-header">unsafe fn <a href="#method.pre_dec" class="fn">pre_dec</a>(&amp;mut self) -&gt; Self</h4></section></summary><div class="docblock"><p>Decrement the pointer by 1, and return its new value.</p>
<p>Equivalent to the C idiom <code>--ptr</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.post_dec" class="method"><a class="src rightside" href="../src/rawpointer/lib.rs.html#117-121">Source</a><h4 class="code-header">unsafe fn <a href="#method.post_dec" class="fn">post_dec</a>(&amp;mut self) -&gt; Self</h4></section></summary><div class="docblock"><p>Decrement the pointer by 1, but return its old value.</p>
<p>Equivalent to the C idiom <code>ptr--</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.inc" class="method"><a class="src rightside" href="../src/rawpointer/lib.rs.html#125-127">Source</a><h4 class="code-header">unsafe fn <a href="#method.inc" class="fn">inc</a>(&amp;mut self)</h4></section></summary><div class="docblock"><p>Increment by 1</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.dec" class="method"><a class="src rightside" href="../src/rawpointer/lib.rs.html#131-133">Source</a><h4 class="code-header">unsafe fn <a href="#method.dec" class="fn">dec</a>(&amp;mut self)</h4></section></summary><div class="docblock"><p>Decrement by 1</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.stride_offset" class="method"><a class="src rightside" href="../src/rawpointer/lib.rs.html#137-139">Source</a><h4 class="code-header">unsafe fn <a href="#method.stride_offset" class="fn">stride_offset</a>(self, s: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.isize.html">isize</a>, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.usize.html">usize</a>) -&gt; Self</h4></section></summary><div class="docblock"><p>Offset the pointer by <code>s</code> multiplied by <code>index</code>.</p>
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.0/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-PointerExt-for-*const+T" class="impl"><a class="src rightside" href="../src/rawpointer/lib.rs.html#142-158">Source</a><a href="#impl-PointerExt-for-*const+T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="trait.PointerExt.html" title="trait rawpointer::PointerExt">PointerExt</a> for <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.pointer.html">*const T</a></h3></section></summary><div class="impl-items"><section id="method.offset" class="method trait-impl"><a class="src rightside" href="../src/rawpointer/lib.rs.html#144-146">Source</a><a href="#method.offset" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#tymethod.offset" class="fn">offset</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.isize.html">isize</a>) -&gt; Self</h4></section><section id="method.add-1" class="method trait-impl"><a class="src rightside" href="../src/rawpointer/lib.rs.html#150-152">Source</a><a href="#method.add-1" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#method.add" class="fn">add</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.usize.html">usize</a>) -&gt; Self</h4></section><section id="method.sub-1" class="method trait-impl"><a class="src rightside" href="../src/rawpointer/lib.rs.html#155-157">Source</a><a href="#method.sub-1" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#method.sub" class="fn">sub</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.usize.html">usize</a>) -&gt; Self</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-PointerExt-for-*mut+T" class="impl"><a class="src rightside" href="../src/rawpointer/lib.rs.html#160-175">Source</a><a href="#impl-PointerExt-for-*mut+T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="trait.PointerExt.html" title="trait rawpointer::PointerExt">PointerExt</a> for <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.pointer.html">*mut T</a></h3></section></summary><div class="impl-items"><section id="method.offset-1" class="method trait-impl"><a class="src rightside" href="../src/rawpointer/lib.rs.html#162-164">Source</a><a href="#method.offset-1" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#tymethod.offset" class="fn">offset</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.isize.html">isize</a>) -&gt; Self</h4></section><section id="method.add-2" class="method trait-impl"><a class="src rightside" href="../src/rawpointer/lib.rs.html#167-169">Source</a><a href="#method.add-2" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#method.add" class="fn">add</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.usize.html">usize</a>) -&gt; Self</h4></section><section id="method.sub-2" class="method trait-impl"><a class="src rightside" href="../src/rawpointer/lib.rs.html#172-174">Source</a><a href="#method.sub-2" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#method.sub" class="fn">sub</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.usize.html">usize</a>) -&gt; Self</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-PointerExt-for-NonNull%3CT%3E" class="impl"><a class="src rightside" href="../src/rawpointer/lib.rs.html#184-189">Source</a><a href="#impl-PointerExt-for-NonNull%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="trait.PointerExt.html" title="trait rawpointer::PointerExt">PointerExt</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/ptr/non_null/struct.NonNull.html" title="struct core::ptr::non_null::NonNull">NonNull</a>&lt;T&gt;</h3></section></summary><div class="docblock"><p><code>NonNull&lt;T&gt;</code> supports the same offsetting methods under the same
safety constraints as the other raw pointer implementations.</p>
<p>There is no difference - both when offsetting <code>*mut T</code> and <code>NonNull&lt;T&gt;</code>,
the offset is only well defined if we remain inside the same object or
one-past the end, and we can never land in a null pointer while obeying
those rules.</p>
</div><div class="impl-items"><section id="method.offset-2" class="method trait-impl"><a class="src rightside" href="../src/rawpointer/lib.rs.html#186-188">Source</a><a href="#method.offset-2" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#tymethod.offset" class="fn">offset</a>(self, i: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.isize.html">isize</a>) -&gt; Self</h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../trait.impl/rawpointer/trait.PointerExt.js" data-ignore-extern-crates="core" async></script></section></div></main></body></html>