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

30 lines
5.9 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="Parse `Uuid`s from string literals at compile time."><title>uuid in uuid - 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="uuid" 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="icon" href="https://www.rust-lang.org/favicon.ico"></head><body class="rustdoc macro"><!--[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><a class="logo-container" href="../uuid/index.html"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../uuid/index.html"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png" alt="logo"></a><h2><a href="../uuid/index.html">uuid</a><span class="version">1.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">uuid</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#usage" title="Usage">Usage</a></li><li><a href="#examples" title="Examples">Examples</a></li><li><a href="#compilation-failures" title="Compilation Failures">Compilation Failures</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate uuid</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">uuid</a></span><h1>Macro <span class="macro">uuid</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/uuid/macros.rs.html#34-88">Source</a> </span></div><pre class="rust item-decl"><code>macro_rules! uuid {
($uuid:expr) =&gt; { ... };
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Parse <a href="https://docs.rs/uuid/*/uuid/struct.Uuid.html"><code>Uuid</code></a>s from string literals at compile time.</p>
<h3 id="usage"><a class="doc-anchor" href="#usage">§</a>Usage</h3>
<p>This macro transforms the string literal representation of a
<a href="https://docs.rs/uuid/*/uuid/struct.Uuid.html"><code>Uuid</code></a> into the bytes representation, raising a compilation
error if it cannot properly be parsed.</p>
<h3 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h3>
<p>Setting a global constant:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">pub const </span>SCHEMA_ATTR_CLASS: Uuid = <span class="macro">uuid!</span>(<span class="string">"00000000-0000-0000-0000-ffff00000000"</span>);
<span class="kw">pub const </span>SCHEMA_ATTR_UUID: Uuid = <span class="macro">uuid!</span>(<span class="string">"00000000-0000-0000-0000-ffff00000001"</span>);
<span class="kw">pub const </span>SCHEMA_ATTR_NAME: Uuid = <span class="macro">uuid!</span>(<span class="string">"00000000-0000-0000-0000-ffff00000002"</span>);</code></pre></div>
<p>Defining a local variable:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>uuid = <span class="macro">uuid!</span>(<span class="string">"urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4"</span>);</code></pre></div>
<p>Using a const variable:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">const </span>UUID_STR: <span class="kw-2">&amp;</span>str = <span class="string">"12345678-1234-5678-1234-567812345678"</span>;
<span class="kw">let </span>UUID = <span class="macro">uuid!</span>(UUID_STR);</code></pre></div>
<h3 id="compilation-failures"><a class="doc-anchor" href="#compilation-failures">§</a>Compilation Failures</h3>
<p>Invalid UUIDs are rejected:</p>
<div class="example-wrap compile_fail"><a href="#" class="tooltip" title="This example deliberately fails to compile"></a><pre class="rust rust-example-rendered"><code><span class="kw">let </span>uuid = <span class="macro">uuid!</span>(<span class="string">"F9168C5E-ZEB2-4FAA-B6BF-329BF39FA1E4"</span>);</code></pre></div>
<p>Enable the feature <code>macro-diagnostics</code> to see the error messages below.</p>
<p>Provides the following compilation error:</p>
<div class="example-wrap"><pre class="language-txt"><code>error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-fA-F-], found Z at 9
|
| let id = uuid!(&quot;F9168C5E-ZEB2-4FAA-B6BF-329BF39FA1E4&quot;);
| ^</code></pre></div></div></details></section></div></main></body></html>