77 lines
7.7 KiB
HTML
77 lines
7.7 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="Generate a corresponding `ULE` type and the relevant `AsULE` implementations for this type"><title>make_ule in zerovec - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="zerovec" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc attr"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">make_ule</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../zerovec/index.html">zerovec</a><span class="version">0.11.5</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">make_<wbr>ule</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate zerovec</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="index.html">zerovec</a></div><h1>Attribute Macro <span class="attr">make_<wbr>ule</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/zerovec_derive/lib.rs.html#31">Source</a> </span></div><pre class="rust item-decl"><code>#[make_ule]</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Generate a corresponding <a href="ule/trait.ULE.html" title="trait zerovec::ule::ULE"><code>ULE</code></a> type and the relevant <a href="ule/trait.AsULE.html" title="trait zerovec::ule::AsULE"><code>AsULE</code></a> implementations for this type</p>
|
|
<p>This can be attached to structs containing only <a href="ule/trait.AsULE.html" title="trait zerovec::ule::AsULE"><code>AsULE</code></a> types, or C-like enums that have <code>#[repr(u8)]</code>
|
|
and all explicit discriminants.</p>
|
|
<p>The type must be <a href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Copy.html" title="trait core::marker::Copy"><code>Copy</code></a>, <a href="https://doc.rust-lang.org/1.93.1/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq"><code>PartialEq</code></a>, and <a href="https://doc.rust-lang.org/1.93.1/core/cmp/trait.Eq.html" title="trait core::cmp::Eq"><code>Eq</code></a>.</p>
|
|
<p><code>#[make_ule]</code> will automatically derive the following traits on the <a href="ule/trait.ULE.html" title="trait zerovec::ule::ULE"><code>ULE</code></a> type:</p>
|
|
<ul>
|
|
<li><a href="https://doc.rust-lang.org/1.93.1/core/cmp/trait.Ord.html" title="trait core::cmp::Ord"><code>Ord</code></a> and <a href="https://doc.rust-lang.org/1.93.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd"><code>PartialOrd</code></a></li>
|
|
<li><a href="maps::ZeroMapKV"><code>ZeroMapKV</code></a></li>
|
|
</ul>
|
|
<p>To disable one of the automatic derives, use <code>#[zerovec::skip_derive(...)]</code> like so: <code>#[zerovec::skip_derive(ZeroMapKV)]</code>.
|
|
<code>Ord</code> and <code>PartialOrd</code> are implemented as a unit and can only be disabled as a group with <code>#[zerovec::skip_derive(Ord)]</code>.</p>
|
|
<p>The following traits are available to derive, but not automatic:</p>
|
|
<ul>
|
|
<li><a href="https://doc.rust-lang.org/1.93.1/core/fmt/macros/derive.Debug.html" title="derive core::fmt::macros::Debug"><code>Debug</code></a></li>
|
|
</ul>
|
|
<p>To enable one of these additional derives, use <code>#[zerovec::derive(...)]</code> like so: <code>#[zerovec::derive(Debug)]</code>.</p>
|
|
<p>In most cases these derives will defer to the impl of the same trait on the current type, so such impls must exist.</p>
|
|
<p>For enums, this attribute will generate a crate-public <code>fn new_from_u8(value: u8) -> Option<Self></code>
|
|
method on the main type that allows one to construct the value from a u8. If this method is desired
|
|
to be more public, it should be wrapped.</p>
|
|
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>zerovec::ZeroVec;
|
|
|
|
<span class="attr">#[zerovec::make_ule(DateULE)]
|
|
#[derive(
|
|
Copy,
|
|
Clone,
|
|
PartialEq,
|
|
Eq,
|
|
Ord,
|
|
PartialOrd,
|
|
serde::Serialize,
|
|
serde::Deserialize,
|
|
)]
|
|
</span><span class="kw">struct </span>Date {
|
|
y: u64,
|
|
m: u8,
|
|
d: u8,
|
|
}
|
|
|
|
<span class="attr">#[derive(serde::Serialize, serde::Deserialize)]
|
|
</span><span class="kw">struct </span>Dates<<span class="lifetime">'a</span>> {
|
|
<span class="attr">#[serde(borrow)]
|
|
</span>dates: ZeroVec<<span class="lifetime">'a</span>, Date>,
|
|
}
|
|
|
|
<span class="kw">let </span>dates = Dates {
|
|
dates: ZeroVec::alloc_from_slice(<span class="kw-2">&</span>[
|
|
Date {
|
|
y: <span class="number">1985</span>,
|
|
m: <span class="number">9</span>,
|
|
d: <span class="number">3</span>,
|
|
},
|
|
Date {
|
|
y: <span class="number">1970</span>,
|
|
m: <span class="number">2</span>,
|
|
d: <span class="number">20</span>,
|
|
},
|
|
Date {
|
|
y: <span class="number">1990</span>,
|
|
m: <span class="number">6</span>,
|
|
d: <span class="number">13</span>,
|
|
},
|
|
]),
|
|
};
|
|
|
|
<span class="kw">let </span>bincode_bytes =
|
|
bincode::serialize(<span class="kw-2">&</span>dates).expect(<span class="string">"Serialization should be successful"</span>);
|
|
|
|
<span class="comment">// Will deserialize without allocations
|
|
</span><span class="kw">let </span>deserialized: Dates = bincode::deserialize(<span class="kw-2">&</span>bincode_bytes)
|
|
.expect(<span class="string">"Deserialization should be successful"</span>);
|
|
|
|
<span class="macro">assert_eq!</span>(deserialized.dates.get(<span class="number">1</span>).unwrap().y, <span class="number">1970</span>);
|
|
<span class="macro">assert_eq!</span>(deserialized.dates.get(<span class="number">2</span>).unwrap().d, <span class="number">13</span>);</code></pre></div>
|
|
<p>Full docs for this proc macro can be found on the <a href="https://docs.rs/zerovec"><code>zerovec</code></a> crate.</p>
|
|
</div></details></section></div></main></body></html> |