Adding large folders

This commit is contained in:
2026-02-26 12:00:21 -05:00
parent 5400d82acd
commit 49701c85ad
47332 changed files with 1942573 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
<!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="Documentation on zero-copy deserialization of locale types."><title>icu_locale_core::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="icu_locale_core" 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 mod"><!--[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="#">Module zerovec</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../icu_locale_core/index.html">icu_<wbr>locale_<wbr>core</a><span class="version">2.1.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module zerovec</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#lookup" title="Lookup">Lookup</a></li><li><a href="#obtain" title="Obtain">Obtain</a><ul><li><a href="#storing-subtags" title="Storing Subtags">Storing Subtags</a></li><li><a href="#storing-strings" title="Storing Strings">Storing Strings</a></li></ul></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate icu_<wbr>locale_<wbr>core</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">icu_locale_core</a></div><h1>Module <span>zerovec</span>&nbsp;<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/icu_locale_core/zerovec.rs.html#5-131">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Documentation on zero-copy deserialization of locale types.</p>
<p><a href="../struct.Locale.html" title="struct icu_locale_core::Locale"><code>Locale</code></a> and <a href="../struct.LanguageIdentifier.html" title="struct icu_locale_core::LanguageIdentifier"><code>LanguageIdentifier</code></a> are highly structured types that cannot be directly
stored in a zero-copy data structure, such as those provided by the <a href="index.html" title="mod icu_locale_core::zerovec"><code>zerovec</code></a> module.
This page explains how to indirectly store these types in a <a href="index.html" title="mod icu_locale_core::zerovec"><code>zerovec</code></a>.</p>
<p>There are two main use cases, which have different solutions:</p>
<ol>
<li><strong>Lookup:</strong> You need to locate a locale in a zero-copy vector, such as when querying a map.</li>
<li><strong>Obtain:</strong> You have a locale stored in a zero-copy vector, and you need to obtain a proper
<a href="../struct.Locale.html" title="struct icu_locale_core::Locale"><code>Locale</code></a> or <a href="../struct.LanguageIdentifier.html" title="struct icu_locale_core::LanguageIdentifier"><code>LanguageIdentifier</code></a> for use elsewhere in your program.</li>
</ol>
<h2 id="lookup"><a class="doc-anchor" href="#lookup">§</a>Lookup</h2>
<p>To perform lookup, store the stringified locale in a canonical BCP-47 form as a byte array,
and then use <a href="../struct.Locale.html#method.strict_cmp" title="method icu_locale_core::Locale::strict_cmp"><code>Locale::strict_cmp()</code></a> to perform an efficient, zero-allocation lookup.</p>
<p>To produce more human-readable serialized output, you can use <code>PotentialUtf8</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>icu::locale::Locale;
<span class="kw">use </span>potential_utf::PotentialUtf8;
<span class="kw">use </span>zerovec::ZeroMap;
<span class="comment">// ZeroMap from locales to integers
</span><span class="kw">let </span>data: <span class="kw-2">&amp;</span>[(<span class="kw-2">&amp;</span>PotentialUtf8, u32)] = <span class="kw-2">&amp;</span>[
(<span class="string">"de-DE-u-hc-h12"</span>.into(), <span class="number">5</span>),
(<span class="string">"en-US-u-ca-buddhist"</span>.into(), <span class="number">10</span>),
(<span class="string">"my-MM"</span>.into(), <span class="number">15</span>),
(<span class="string">"sr-Cyrl-ME"</span>.into(), <span class="number">20</span>),
(<span class="string">"zh-TW"</span>.into(), <span class="number">25</span>),
];
<span class="kw">let </span>zm: ZeroMap&lt;PotentialUtf8, u32&gt; = data.iter().copied().collect();
<span class="comment">// Get the value associated with a locale
</span><span class="kw">let </span>loc: Locale = <span class="string">"en-US-u-ca-buddhist"</span>.parse().unwrap();
<span class="kw">let </span>value = zm.get_copied_by(|uvstr| loc.strict_cmp(uvstr).reverse());
<span class="macro">assert_eq!</span>(value, <span class="prelude-val">Some</span>(<span class="number">10</span>));</code></pre></div><h2 id="obtain"><a class="doc-anchor" href="#obtain">§</a>Obtain</h2>
<p>Obtaining a <a href="../struct.Locale.html" title="struct icu_locale_core::Locale"><code>Locale</code></a> or <a href="../struct.LanguageIdentifier.html" title="struct icu_locale_core::LanguageIdentifier"><code>LanguageIdentifier</code></a> is not generally a zero-copy operation, since
both of these types may require memory allocation. If possible, architect your code such that
you do not need to obtain a structured type.</p>
<p>If you need the structured type, such as if you need to manipulate it in some way, there are two
options: storing subtags, and storing a string for parsing.</p>
<h3 id="storing-subtags"><a class="doc-anchor" href="#storing-subtags">§</a>Storing Subtags</h3>
<p>If the data being stored only contains a limited number of subtags, you can store them as a
tuple, and then construct the <a href="../struct.LanguageIdentifier.html" title="struct icu_locale_core::LanguageIdentifier"><code>LanguageIdentifier</code></a> externally.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>icu::locale::subtags::{Language, Region, Script};
<span class="kw">use </span>icu::locale::LanguageIdentifier;
<span class="kw">use </span>icu::locale::{
langid,
subtags::{language, region, script},
};
<span class="kw">use </span>zerovec::ZeroMap;
<span class="comment">// ZeroMap from integer to LSR (language-script-region)
</span><span class="kw">let </span>zm: ZeroMap&lt;u32, (Language, <span class="prelude-ty">Option</span>&lt;Script&gt;, <span class="prelude-ty">Option</span>&lt;Region&gt;)&gt; = [
(<span class="number">5</span>, (<span class="macro">language!</span>(<span class="string">"de"</span>), <span class="prelude-val">None</span>, <span class="prelude-val">Some</span>(<span class="macro">region!</span>(<span class="string">"DE"</span>)))),
(<span class="number">10</span>, (<span class="macro">language!</span>(<span class="string">"en"</span>), <span class="prelude-val">None</span>, <span class="prelude-val">Some</span>(<span class="macro">region!</span>(<span class="string">"US"</span>)))),
(<span class="number">15</span>, (<span class="macro">language!</span>(<span class="string">"my"</span>), <span class="prelude-val">None</span>, <span class="prelude-val">Some</span>(<span class="macro">region!</span>(<span class="string">"MM"</span>)))),
(
<span class="number">20</span>,
(<span class="macro">language!</span>(<span class="string">"sr"</span>), <span class="prelude-val">Some</span>(<span class="macro">script!</span>(<span class="string">"Cyrl"</span>)), <span class="prelude-val">Some</span>(<span class="macro">region!</span>(<span class="string">"ME"</span>))),
),
(<span class="number">25</span>, (<span class="macro">language!</span>(<span class="string">"zh"</span>), <span class="prelude-val">None</span>, <span class="prelude-val">Some</span>(<span class="macro">region!</span>(<span class="string">"TW"</span>)))),
]
.into_iter()
.collect();
<span class="comment">// Construct a LanguageIdentifier from a tuple entry
</span><span class="kw">let </span>lid: LanguageIdentifier =
zm.get_copied(<span class="kw-2">&amp;</span><span class="number">25</span>).expect(<span class="string">"element is present"</span>).into();
<span class="macro">assert_eq!</span>(lid, <span class="macro">langid!</span>(<span class="string">"zh-TW"</span>));</code></pre></div><h3 id="storing-strings"><a class="doc-anchor" href="#storing-strings">§</a>Storing Strings</h3>
<p>If it is necessary to store and obtain an arbitrary locale, it is currently recommended to
store a BCP-47 string and parse it when needed.</p>
<p>Since the string is stored in an unparsed state, it is not safe to <code>unwrap</code> the result from
<code>Locale::try_from_utf8()</code>. See <a href="https://github.com/unicode-org/icu4x/issues/831">icu4x#831</a>
for a discussion on potential data models that could ensure that the locale is valid during
deserialization.</p>
<p>As above, to produce more human-readable serialized output, you can use <code>PotentialUtf8</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>icu::locale::langid;
<span class="kw">use </span>icu::locale::Locale;
<span class="kw">use </span>potential_utf::PotentialUtf8;
<span class="kw">use </span>zerovec::ZeroMap;
<span class="comment">// ZeroMap from integer to locale string
</span><span class="kw">let </span>data: <span class="kw-2">&amp;</span>[(u32, <span class="kw-2">&amp;</span>PotentialUtf8)] = <span class="kw-2">&amp;</span>[
(<span class="number">5</span>, <span class="string">"de-DE-u-hc-h12"</span>.into()),
(<span class="number">10</span>, <span class="string">"en-US-u-ca-buddhist"</span>.into()),
(<span class="number">15</span>, <span class="string">"my-MM"</span>.into()),
(<span class="number">20</span>, <span class="string">"sr-Cyrl-ME"</span>.into()),
(<span class="number">25</span>, <span class="string">"zh-TW"</span>.into()),
(<span class="number">30</span>, <span class="string">"INVALID"</span>.into()),
];
<span class="kw">let </span>zm: ZeroMap&lt;u32, PotentialUtf8&gt; = data.iter().copied().collect();
<span class="comment">// Construct a Locale by parsing the string.
</span><span class="kw">let </span>value = zm.get(<span class="kw-2">&amp;</span><span class="number">25</span>).expect(<span class="string">"element is present"</span>);
<span class="kw">let </span>loc = Locale::try_from_utf8(value);
<span class="macro">assert_eq!</span>(loc, <span class="prelude-val">Ok</span>(<span class="macro">langid!</span>(<span class="string">"zh-TW"</span>).into()));
<span class="comment">// Invalid entries are fallible
</span><span class="kw">let </span>err_value = zm.get(<span class="kw-2">&amp;</span><span class="number">30</span>).expect(<span class="string">"element is present"</span>);
<span class="kw">let </span>err_loc = Locale::try_from_utf8(err_value);
<span class="macro">assert!</span>(err_loc.is_err());</code></pre></div></div></details></section></div></main></body></html>

View File

@@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {};