-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
31 lines (27 loc) · 7.48 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!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="A crate used for calculating offsets of struct members and their spans."><title>memoffset - 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-46132b98.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="memoffset" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0 (4d91de4e4 2025-02-17)" data-channel="1.85.0" data-search-js="search-75f5ac3e.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="../memoffset/index.html">memoffset</a><span class="version">0.9.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="#examples" title="Examples">Examples</a></li></ul><h3><a href="#modules">Crate Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#macros" title="Macros">Macros</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>memoffset</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/memoffset/lib.rs.html#21-86">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A crate used for calculating offsets of struct members and their spans.</p>
<p>This functionality currently can not be used in compile time code such as <code>const</code> or <code>const fn</code> definitions.</p>
<h3 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h3>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>memoffset::{offset_of, span_of};
<span class="attr">#[repr(C, packed)]
</span><span class="kw">struct </span>HelpMeIAmTrappedInAStructFactory {
help_me_before_they_: [u8; <span class="number">15</span>],
a: u32
}
<span class="macro">assert_eq!</span>(<span class="macro">offset_of!</span>(HelpMeIAmTrappedInAStructFactory, a), <span class="number">15</span>);
<span class="macro">assert_eq!</span>(<span class="macro">span_of!</span>(HelpMeIAmTrappedInAStructFactory, a), <span class="number">15</span>..<span class="number">19</span>);
<span class="macro">assert_eq!</span>(<span class="macro">span_of!</span>(HelpMeIAmTrappedInAStructFactory, help_me_before_they_ .. a), <span class="number">0</span>..<span class="number">15</span>);</code></pre></div>
<p>This functionality can be useful, for example, for checksum calculations:</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="attr">#[repr(C, packed)]
</span><span class="kw">struct </span>Message {
header: MessageHeader,
fragment_index: u32,
fragment_count: u32,
payload: [u8; <span class="number">1024</span>],
checksum: u16
}
<span class="kw">let </span>checksum_range = <span class="kw-2">&</span>raw[<span class="macro">span_of!</span>(Message, header..checksum)];
<span class="kw">let </span>checksum = crc16(checksum_range);</code></pre></div>
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="offset_of/index.html" title="mod memoffset::offset_of">offset_<wbr>of</a><span title="Restricted Visibility"> 🔒</span> </div></li><li><div class="item-name"><a class="mod" href="raw_field/index.html" title="mod memoffset::raw_field">raw_<wbr>field</a><span title="Restricted Visibility"> 🔒</span> </div></li><li><div class="item-name"><a class="mod" href="span_of/index.html" title="mod memoffset::span_of">span_of</a><span title="Restricted Visibility"> 🔒</span> </div></li></ul><h2 id="macros" class="section-header">Macros<a href="#macros" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="macro" href="macro.offset_of.html" title="macro memoffset::offset_of">offset_<wbr>of</a></div><div class="desc docblock-short">Calculates the offset of the specified field from the start of the named struct.</div></li><li><div class="item-name"><a class="macro" href="macro.offset_of_tuple.html" title="macro memoffset::offset_of_tuple">offset_<wbr>of_<wbr>tuple</a></div><div class="desc docblock-short">Calculates the offset of the specified field from the start of the tuple.</div></li><li><div class="item-name"><a class="macro" href="macro.offset_of_union.html" title="macro memoffset::offset_of_union">offset_<wbr>of_<wbr>union</a></div><div class="desc docblock-short">Calculates the offset of the specified union member from the start of the union.</div></li><li><div class="item-name"><a class="macro" href="macro.raw_field.html" title="macro memoffset::raw_field">raw_<wbr>field</a></div><div class="desc docblock-short">Computes a const raw pointer to the given field of the given base pointer
to the given parent type.</div></li><li><div class="item-name"><a class="macro" href="macro.raw_field_tuple.html" title="macro memoffset::raw_field_tuple">raw_<wbr>field_<wbr>tuple</a></div><div class="desc docblock-short">Computes a const raw pointer to the given field of the given base pointer
to the given parent tuple type.</div></li><li><div class="item-name"><a class="macro" href="macro.raw_field_union.html" title="macro memoffset::raw_field_union">raw_<wbr>field_<wbr>union</a></div><div class="desc docblock-short">Computes a const raw pointer to the given field of the given base pointer
to the given parent tuple type.</div></li><li><div class="item-name"><a class="macro" href="macro.span_of.html" title="macro memoffset::span_of">span_of</a></div><div class="desc docblock-short">Produces a range instance representing the sub-slice containing the specified member.</div></li></ul></section></div></main></body></html>