Files
flexiber/delog/hex/fn.HexStr.html
2025-09-26 12:35:52 +00:00

27 lines
5.0 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="Explicitly construct a newtype to format with."><title>HexStr in delog::hex - 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" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-84e720fa.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="delog" data-themes="" data-resource-suffix="" data-rustdoc-version="1.89.0 (29483883e 2025-08-04)" data-channel="1.89.0" data-search-js="search-92309212.js" data-settings-js="settings-5514c975.js" ><script src="../../static.files/storage-4e99c027.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-fd3af306.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-32bb7600.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 fn"><!--[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="../../delog/index.html">delog</a><span class="version">0.1.8</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In delog::<wbr>hex</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">delog</a>::<wbr><a href="index.html">hex</a></div><h1>Function <span class="fn">HexStr</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/delog/hex.rs.html#187-193">Source</a> </span></div><pre class="rust item-decl"><code>pub fn HexStr&lt;T: ?<a class="trait" href="https://doc.rust-lang.org/1.89.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, U: <a class="trait" href="trait.Unsigned.html" title="trait delog::hex::Unsigned">Unsigned</a>, S: <a class="trait" href="trait.Separator.html" title="trait delog::hex::Separator">Separator</a>&gt;(
value: <a class="primitive" href="https://doc.rust-lang.org/1.89.0/core/primitive.reference.html">&amp;T</a>,
) -&gt; <a class="struct" href="struct.HexStr.html" title="struct delog::hex::HexStr">HexStr</a>&lt;'_, T, U, S&gt;</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Explicitly construct a newtype to format with.</p>
<p>The first generic parameter specifies the block size in bytes, the second parameter
the separator string.</p>
<p>This function is just here for documentation of what the <code>hex_str!</code> macro
does internally (using the undocumented <code>typeint!</code> and <code>typesep!</code> macros).</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>delog::hex::{HexStr, Separator, Unsigned};
<span class="comment">// typeint!(U3, 3);
</span><span class="kw">struct </span>U3 {}
<span class="kw">impl </span>Unsigned <span class="kw">for </span>U3 {
<span class="kw">const </span>N: usize = <span class="number">3</span>;
}
<span class="comment">// typesep!(Pipe, "|");
</span><span class="kw">struct </span>Pipe {}
<span class="kw">impl </span>Separator <span class="kw">for </span>Pipe {
<span class="kw">const </span>SEPARATOR: <span class="kw-2">&amp;</span><span class="lifetime">'static </span>str = <span class="string">"|"</span>;
}
<span class="kw">let </span>four_bytes = <span class="kw-2">&amp;</span>[<span class="number">7u8</span>, <span class="number">0xA1</span>, <span class="number">255</span>, <span class="number">0xC7</span>];
<span class="kw">let </span>hex_str = HexStr::&lt;<span class="kw">_</span>, U3, Pipe&gt;(four_bytes);
<span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">"{}"</span>, hex_str), <span class="string">"07A1FF|C7"</span>);</code></pre></div>
</div></details></section></div></main></body></html>