41 lines
8.1 KiB
HTML
41 lines
8.1 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="`tinystr` is a utility crate of the `ICU4X` project."><title>tinystr - 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="tinystr" 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="../crates.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 mod crate"><!--[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="#">Crate tinystr</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../tinystr/index.html">tinystr</a><span class="version">0.8.2</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><li><a href="#details" title="Details">Details</a></li></ul><h3><a href="#macros">Crate Items</a></h3><ul class="block"><li><a href="#macros" title="Macros">Macros</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"></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"><h1>Crate <span>tinystr</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/tinystr/lib.rs.html#5-114">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><code>tinystr</code> is a utility crate of the <a href="../icu/index.html"><code>ICU4X</code></a> project.</p>
|
|
<p>It includes <a href="struct.TinyAsciiStr.html" title="struct tinystr::TinyAsciiStr"><code>TinyAsciiStr</code></a>, a core API for representing small ASCII-only bounded length strings.</p>
|
|
<p>It is optimized for operations on strings of size 8 or smaller. When use cases involve comparison
|
|
and conversion of strings for lowercase/uppercase/titlecase, or checking
|
|
numeric/alphabetic/alphanumeric, <code>TinyAsciiStr</code> is the edge performance library.</p>
|
|
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tinystr::TinyAsciiStr;
|
|
|
|
<span class="kw">let </span>s1: TinyAsciiStr<<span class="number">4</span>> = <span class="string">"tEsT"</span>.parse().expect(<span class="string">"Failed to parse."</span>);
|
|
|
|
<span class="macro">assert_eq!</span>(s1, <span class="string">"tEsT"</span>);
|
|
<span class="macro">assert_eq!</span>(s1.to_ascii_uppercase(), <span class="string">"TEST"</span>);
|
|
<span class="macro">assert_eq!</span>(s1.to_ascii_lowercase(), <span class="string">"test"</span>);
|
|
<span class="macro">assert_eq!</span>(s1.to_ascii_titlecase(), <span class="string">"Test"</span>);
|
|
<span class="macro">assert!</span>(s1.is_ascii_alphanumeric());
|
|
<span class="macro">assert!</span>(!s1.is_ascii_numeric());
|
|
|
|
<span class="kw">let </span>s2 = TinyAsciiStr::<<span class="number">8</span>>::try_from_raw(<span class="kw-2">*</span><span class="string">b"New York"</span>)
|
|
.expect(<span class="string">"Failed to parse."</span>);
|
|
|
|
<span class="macro">assert_eq!</span>(s2, <span class="string">"New York"</span>);
|
|
<span class="macro">assert_eq!</span>(s2.to_ascii_uppercase(), <span class="string">"NEW YORK"</span>);
|
|
<span class="macro">assert_eq!</span>(s2.to_ascii_lowercase(), <span class="string">"new york"</span>);
|
|
<span class="macro">assert_eq!</span>(s2.to_ascii_titlecase(), <span class="string">"New york"</span>);
|
|
<span class="macro">assert!</span>(!s2.is_ascii_alphanumeric());</code></pre></div><h2 id="details"><a class="doc-anchor" href="#details">§</a>Details</h2>
|
|
<p>When strings are of size 8 or smaller, the struct transforms the strings as <code>u32</code>/<code>u64</code> and uses
|
|
bitmasking to provide basic string manipulation operations:</p>
|
|
<ul>
|
|
<li><code>is_ascii_numeric</code></li>
|
|
<li><code>is_ascii_alphabetic</code></li>
|
|
<li><code>is_ascii_alphanumeric</code></li>
|
|
<li><code>to_ascii_lowercase</code></li>
|
|
<li><code>to_ascii_uppercase</code></li>
|
|
<li><code>to_ascii_titlecase</code></li>
|
|
<li><code>PartialEq</code></li>
|
|
</ul>
|
|
<p><code>TinyAsciiStr</code> will fall back to <code>u8</code> character manipulation for strings of length greater than 8.</p>
|
|
</div></details><h2 id="macros" class="section-header">Macros<a href="#macros" class="anchor">§</a></h2><dl class="item-table"><dt><a class="macro" href="macro.tinystr.html" title="macro tinystr::tinystr">tinystr</a></dt></dl><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.TinyAsciiStr.html" title="struct tinystr::TinyAsciiStr">Tiny<wbr>Ascii<wbr>Str</a></dt><dt><a class="struct" href="struct.UnvalidatedTinyAsciiStr.html" title="struct tinystr::UnvalidatedTinyAsciiStr">Unvalidated<wbr>Tiny<wbr>Ascii<wbr>Str</a></dt><dd>A fixed-length bytes array that is expected to be an ASCII string but does not enforce that invariant.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.ParseError.html" title="enum tinystr::ParseError">Parse<wbr>Error</a></dt></dl><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><dl class="item-table"><dt><a class="type" href="type.TinyStr4.html" title="type tinystr::TinyStr4">Tiny<wbr>Str4</a></dt><dd>These are temporary compatability reexports that will be removed
|
|
in a future version.</dd><dt><a class="type" href="type.TinyStr8.html" title="type tinystr::TinyStr8">Tiny<wbr>Str8</a></dt><dd>These are temporary compatability reexports that will be removed
|
|
in a future version.</dd><dt><a class="type" href="type.TinyStr16.html" title="type tinystr::TinyStr16">Tiny<wbr>Str16</a></dt><dd>These are temporary compatability reexports that will be removed
|
|
in a future version.</dd></dl><script type="text/json" id="notable-traits-data">{"&[u8]":"<h3>Notable traits for <code>&[<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.93.1/std/primitive.u8.html\">u8</a>]</code></h3><pre><code><div class=\"where\">impl <a class=\"trait\" href=\"https://doc.rust-lang.org/1.93.1/std/io/trait.Read.html\" title=\"trait std::io::Read\">Read</a> for &[<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.93.1/std/primitive.u8.html\">u8</a>]</div>"}</script></section></div></main></body></html> |