summaryrefslogtreecommitdiffstats
path: root/vendor/tinystr
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/tinystr')
-rw-r--r--vendor/tinystr/.cargo-checksum.json2
-rw-r--r--vendor/tinystr/Cargo.toml37
-rw-r--r--vendor/tinystr/LICENSE79
-rw-r--r--vendor/tinystr/README.md4
-rw-r--r--vendor/tinystr/benches/common/mod.rs24
-rw-r--r--vendor/tinystr/benches/construct.rs24
-rw-r--r--vendor/tinystr/benches/overview.rs74
-rw-r--r--vendor/tinystr/src/ascii.rs12
-rw-r--r--vendor/tinystr/src/databake.rs29
-rw-r--r--vendor/tinystr/src/lib.rs2
-rw-r--r--vendor/tinystr/src/serde.rs2
-rw-r--r--vendor/tinystr/src/ule.rs48
-rw-r--r--vendor/tinystr/src/unvalidated.rs104
13 files changed, 247 insertions, 194 deletions
diff --git a/vendor/tinystr/.cargo-checksum.json b/vendor/tinystr/.cargo-checksum.json
index 86027edd3..8608630b3 100644
--- a/vendor/tinystr/.cargo-checksum.json
+++ b/vendor/tinystr/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"b28bb188b7c3b68f9d9a710921a42f337bd2e07eb7588d983b20724f64d6a8c8","LICENSE":"4ad7541d66a407234e2c84902124cef325c29f3e966353efdb800bedb8b8da21","README.md":"8e79e986c696d6010a578b2872ee4144d86e26d30a409167ff2cf2af551ef231","benches/common/mod.rs":"7a31f89cb68cec2574287636ac22fe3fc86a66688b8b1e99700a5da692bd485e","benches/construct.rs":"0e0e7c1459dd3efea0c734a999318078b53e18c3389c74a1ff5a226cd3d05cca","benches/overview.rs":"296d19b32a2d52e449140771d89f9c099d19177eb84e1395c942469d51c4c3f8","benches/read.rs":"cbf349393a50eb90e7ba53906f98a689d585242292f867a37acf6842263af4d9","benches/serde.rs":"5c88866d08c07088b82dbd5472e6276c632d11e064417f5d8f2025a5ade867f0","src/ascii.rs":"403408b47d813110e840d4db688145c37a17fbcbff173038d9e3743aa712b321","src/asciibyte.rs":"fa29de7403c0424c52c2f30bb47002b9abf4bd08b302c411ffe679d3decfb8de","src/databake.rs":"9f29e30e6deec989822cbdf01f5165e098fa544cf7e49ccea3f5de827648fc1e","src/error.rs":"e0cbc912258d6e56aad148404d7cc3213d89736fa9ebe56c41f6cb0df7b2dd63","src/int_ops.rs":"c2be314d19dd41cf18fb3589901d7e58ee32fe3f764fb6a66b08a1e005336406","src/lib.rs":"7ddbd83bcb9091495de3c4a7eb7ecc25313c54991be8b463d67a7c2e97c076b6","src/macros.rs":"3fe76e258b0db2896284bcf4f50a4ac35b7efc542649b4c9f13c6e71c5957ae4","src/serde.rs":"0bd6bbe2ee8195aea68dd235d59b94faa3419aaeb8939e3220dd64bd888873f5","src/ule.rs":"139543634949a95405bc49862840b0794db089abed6efe66533858376cae180f","tests/serde.rs":"cf8cee82f731928375888d1b5e7e5e50368d3e16ce372fced230c9b1ee2a7451"},"package":"7ac3f5b6856e931e15e07b478e98c8045239829a65f9156d4fa7e7788197a5ef"} \ No newline at end of file
+{"files":{"Cargo.toml":"6beb3627cfc6a20263af586baaf821337375279823e2808ff2e729dd4c8a908a","LICENSE":"853f87c96f3d249f200fec6db1114427bc8bdf4afddc93c576956d78152ce978","README.md":"b7b7a33a29865bc653a6696b079c1527ba61cd58a815fc792ed6fa5bfc680ad5","benches/common/mod.rs":"7e709fcabc2f96b10d3db8968ef3ea7fcc25e88211ce97b64b2126c7a0d7387a","benches/construct.rs":"f61e87e177dd994b700303b75c499a3e95183bb5ff6566889eb085825238dff4","benches/overview.rs":"cac8cfdcf397644ada6bc0bab8f92afc15071b0a64e3119aee4153b616eb9cff","benches/read.rs":"cbf349393a50eb90e7ba53906f98a689d585242292f867a37acf6842263af4d9","benches/serde.rs":"5c88866d08c07088b82dbd5472e6276c632d11e064417f5d8f2025a5ade867f0","src/ascii.rs":"7ad651b33c221a656a48eb44980d9b94bb0a681e79f4955648764968d3a5d62f","src/asciibyte.rs":"fa29de7403c0424c52c2f30bb47002b9abf4bd08b302c411ffe679d3decfb8de","src/databake.rs":"0dc32b7901f73a09357257a57f6150ba7197a88c489c2542081fcdc12336dca8","src/error.rs":"e0cbc912258d6e56aad148404d7cc3213d89736fa9ebe56c41f6cb0df7b2dd63","src/int_ops.rs":"c2be314d19dd41cf18fb3589901d7e58ee32fe3f764fb6a66b08a1e005336406","src/lib.rs":"97cd144b22a402746f4251afc061af075be9d3e6e111d3835f1c1e5cb465d469","src/macros.rs":"3fe76e258b0db2896284bcf4f50a4ac35b7efc542649b4c9f13c6e71c5957ae4","src/serde.rs":"a2c2120043e3334e1cca6fe0fd045ae035849fe6bb33ab0668804334606165dc","src/ule.rs":"52d76c91eeb73eb1885a0b1f40903fc68ea83f7a8b953a71b072eb7d242b3c63","src/unvalidated.rs":"6e41ce55d5f9a2a73f59467c5aff467d12f2b5f297695f109c09812595492efe","tests/serde.rs":"cf8cee82f731928375888d1b5e7e5e50368d3e16ce372fced230c9b1ee2a7451"},"package":"d5d0e245e80bdc9b4e5356fc45a72184abbc3861992603f515270e9340f5a219"} \ No newline at end of file
diff --git a/vendor/tinystr/Cargo.toml b/vendor/tinystr/Cargo.toml
index 284ce6d2d..f82bb66b8 100644
--- a/vendor/tinystr/Cargo.toml
+++ b/vendor/tinystr/Cargo.toml
@@ -11,10 +11,12 @@
[package]
edition = "2021"
+rust-version = "1.66"
name = "tinystr"
-version = "0.7.1"
+version = "0.7.4"
authors = ["The ICU4X Project Developers"]
include = [
+ "data/**/*",
"src/**/*",
"examples/**/*",
"benches/**/*",
@@ -24,6 +26,7 @@ include = [
"README.md",
]
description = "A small ASCII-only bounded length string representation."
+readme = "README.md"
keywords = [
"string",
"str",
@@ -32,18 +35,20 @@ keywords = [
"no_std",
]
categories = ["data-structures"]
-license = "Unicode-DFS-2016"
+license-file = "LICENSE"
repository = "https://github.com/unicode-org/icu4x"
-resolver = "2"
-[package.metadata.workspaces]
-independent = true
+[package.metadata.cargo-all-features]
+denylist = ["bench"]
[package.metadata.docs.rs]
all-features = true
-[package.metadata.cargo-all-features]
-denylist = ["bench"]
+[package.metadata.workspaces]
+independent = true
+
+[lib]
+bench = false
[[test]]
name = "serde"
@@ -72,8 +77,9 @@ required-features = [
]
[dependencies.databake]
-version = "0.1.3"
+version = "0.1.6"
optional = true
+default-features = false
[dependencies.displaydoc]
version = "0.2.3"
@@ -86,18 +92,17 @@ optional = true
default-features = false
[dependencies.zerovec]
-version = "0.9.2"
+version = "0.10.0"
optional = true
+default-features = false
[dev-dependencies.bincode]
version = "1.3"
-[dev-dependencies.criterion]
-version = "0.3"
-
[dev-dependencies.postcard]
version = "1.0.0"
features = ["use-std"]
+default-features = false
[dev-dependencies.rand]
version = "0.8.5"
@@ -108,13 +113,11 @@ version = "1.0"
features = ["alloc"]
default-features = false
-[dev-dependencies.tinystr_old]
-version = "0.4"
-features = ["serde"]
-package = "tinystr"
-
[features]
alloc = []
bench = []
default = ["alloc"]
std = []
+
+[target."cfg(not(target_arch = \"wasm32\"))".dev-dependencies.criterion]
+version = "0.4"
diff --git a/vendor/tinystr/LICENSE b/vendor/tinystr/LICENSE
index 9858d01ab..9845aa5f4 100644
--- a/vendor/tinystr/LICENSE
+++ b/vendor/tinystr/LICENSE
@@ -1,49 +1,42 @@
-UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE
-
-See Terms of Use <https://www.unicode.org/copyright.html>
-for definitions of Unicode Inc.’s Data Files and Software.
-
-NOTICE TO USER: Carefully read the following legal agreement.
-BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S
-DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"),
-YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
-TERMS AND CONDITIONS OF THIS AGREEMENT.
-IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE
-THE DATA FILES OR SOFTWARE.
+UNICODE LICENSE V3
COPYRIGHT AND PERMISSION NOTICE
-Copyright © 1991-2022 Unicode, Inc. All rights reserved.
-Distributed under the Terms of Use in https://www.unicode.org/copyright.html.
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of the Unicode data files and any associated documentation
-(the "Data Files") or Unicode software and any associated documentation
-(the "Software") to deal in the Data Files or Software
-without restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, and/or sell copies of
-the Data Files or Software, and to permit persons to whom the Data Files
-or Software are furnished to do so, provided that either
-(a) this copyright and permission notice appear with all copies
-of the Data Files or Software, or
-(b) this copyright and permission notice appear in associated
-Documentation.
-
-THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF
-ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
-WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT OF THIRD PARTY RIGHTS.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
-NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
-DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THE DATA FILES OR SOFTWARE.
-
-Except as contained in this notice, the name of a copyright holder
-shall not be used in advertising or otherwise to promote the sale,
-use or other dealings in these Data Files or Software without prior
-written authorization of the copyright holder.
+Copyright © 2020-2023 Unicode, Inc.
+
+NOTICE TO USER: Carefully read the following legal agreement. BY
+DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
+SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
+TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
+DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of data files and any associated documentation (the "Data Files") or
+software and any associated documentation (the "Software") to deal in the
+Data Files or Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, and/or sell
+copies of the Data Files or Software, and to permit persons to whom the
+Data Files or Software are furnished to do so, provided that either (a)
+this copyright and permission notice appear with all copies of the Data
+Files or Software, or (b) this copyright and permission notice appear in
+associated Documentation.
+
+THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+THIRD PARTY RIGHTS.
+
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
+BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
+OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
+FILES OR SOFTWARE.
+
+Except as contained in this notice, the name of a copyright holder shall
+not be used in advertising or otherwise to promote the sale, use or other
+dealings in these Data Files or Software without prior written
+authorization of the copyright holder.
diff --git a/vendor/tinystr/README.md b/vendor/tinystr/README.md
index 5f9a8142b..92b74c0d1 100644
--- a/vendor/tinystr/README.md
+++ b/vendor/tinystr/README.md
@@ -1,5 +1,7 @@
# tinystr [![crates.io](https://img.shields.io/crates/v/tinystr)](https://crates.io/crates/tinystr)
+<!-- cargo-rdme start -->
+
`tinystr` is a utility crate of the [`ICU4X`] project.
It includes [`TinyAsciiStr`], a core API for representing small ASCII-only bounded length strings.
@@ -48,6 +50,8 @@ bitmasking to provide basic string manipulation operations:
[`ICU4X`]: ../icu/index.html
+<!-- cargo-rdme end -->
+
## More Information
For more information on development, authorship, contributing etc. please visit [`ICU4X home page`](https://github.com/unicode-org/icu4x).
diff --git a/vendor/tinystr/benches/common/mod.rs b/vendor/tinystr/benches/common/mod.rs
index 07654e1d9..84090b6c2 100644
--- a/vendor/tinystr/benches/common/mod.rs
+++ b/vendor/tinystr/benches/common/mod.rs
@@ -37,43 +37,19 @@ macro_rules! bench_block {
let mut group4 = $c.benchmark_group(&format!("{}/4", $name));
group4.bench_function("String", $action!(String, STRINGS_4));
group4.bench_function("TinyAsciiStr<4>", $action!(TinyAsciiStr<4>, STRINGS_4));
- group4.bench_function(
- "tinystr_old::TinyStr4",
- $action!(tinystr_old::TinyStr4, STRINGS_4),
- );
group4.bench_function("TinyAsciiStr<8>", $action!(TinyAsciiStr<8>, STRINGS_4));
- group4.bench_function(
- "tinystr_old::TinyStr8",
- $action!(tinystr_old::TinyStr8, STRINGS_4),
- );
group4.bench_function("TinyAsciiStr<16>", $action!(TinyAsciiStr<16>, STRINGS_4));
- group4.bench_function(
- "tinystr_old::TinyStr16",
- $action!(tinystr_old::TinyStr16, STRINGS_4),
- );
group4.finish();
let mut group8 = $c.benchmark_group(&format!("{}/8", $name));
group8.bench_function("String", $action!(String, STRINGS_8));
group8.bench_function("TinyAsciiStr<8>", $action!(TinyAsciiStr<8>, STRINGS_8));
group8.bench_function("TinyAsciiStr<16>", $action!(TinyAsciiStr<16>, STRINGS_8));
- group8.bench_function(
- "tinystr_old::TinyStr8",
- $action!(tinystr_old::TinyStr8, STRINGS_8),
- );
- group8.bench_function(
- "tinystr_old::TinyStr16",
- $action!(tinystr_old::TinyStr16, STRINGS_8),
- );
group8.finish();
let mut group16 = $c.benchmark_group(&format!("{}/16", $name));
group16.bench_function("String", $action!(String, STRINGS_16));
group16.bench_function("TinyAsciiStr<16>", $action!(TinyAsciiStr<16>, STRINGS_16));
- group16.bench_function(
- "tinystr_old::TinyStr16",
- $action!(tinystr_old::TinyStr16, STRINGS_16),
- );
group16.finish();
};
}
diff --git a/vendor/tinystr/benches/construct.rs b/vendor/tinystr/benches/construct.rs
index 145e721e1..19b18121f 100644
--- a/vendor/tinystr/benches/construct.rs
+++ b/vendor/tinystr/benches/construct.rs
@@ -47,41 +47,17 @@ fn construct_from_bytes(c: &mut Criterion) {
let mut group4 = c.benchmark_group("construct_from_bytes/4");
group4.bench_function("TinyAsciiStr<4>", cfu!(TinyAsciiStr<4>, STRINGS_4));
- group4.bench_function(
- "tinystr_old::TinyStr4",
- cfu!(tinystr_old::TinyStr4, STRINGS_4),
- );
group4.bench_function("TinyAsciiStr<8>", cfu!(TinyAsciiStr<8>, STRINGS_4));
- group4.bench_function(
- "tinystr_old::TinyStr8",
- cfu!(tinystr_old::TinyStr8, STRINGS_4),
- );
group4.bench_function("TinyAsciiStr<16>", cfu!(TinyAsciiStr<16>, STRINGS_4));
- group4.bench_function(
- "tinystr_old::TinyStr16",
- cfu!(tinystr_old::TinyStr16, STRINGS_4),
- );
group4.finish();
let mut group8 = c.benchmark_group("construct_from_bytes/8");
group8.bench_function("TinyAsciiStr<8>", cfu!(TinyAsciiStr<8>, STRINGS_8));
- group8.bench_function(
- "tinystr_old::TinyStr8",
- cfu!(tinystr_old::TinyStr8, STRINGS_8),
- );
group8.bench_function("TinyAsciiStr<16>", cfu!(TinyAsciiStr<16>, STRINGS_8));
- group8.bench_function(
- "tinystr_old::TinyStr16",
- cfu!(tinystr_old::TinyStr16, STRINGS_8),
- );
group8.finish();
let mut group16 = c.benchmark_group("construct_from_bytes/16");
group16.bench_function("TinyAsciiStr<16>", cfu!(TinyAsciiStr<16>, STRINGS_16));
- group16.bench_function(
- "tinystr_old::TinyStr16",
- cfu!(tinystr_old::TinyStr16, STRINGS_16),
- );
group16.finish();
}
diff --git a/vendor/tinystr/benches/overview.rs b/vendor/tinystr/benches/overview.rs
index 4911832ec..ccdd21ac4 100644
--- a/vendor/tinystr/benches/overview.rs
+++ b/vendor/tinystr/benches/overview.rs
@@ -11,9 +11,6 @@ use criterion::criterion_main;
use criterion::Criterion;
use tinystr::TinyAsciiStr;
-use tinystr_old::TinyStr16;
-use tinystr_old::TinyStr4;
-use tinystr_old::TinyStr8;
fn overview(c: &mut Criterion) {
let mut g = c.benchmark_group("overview");
@@ -35,23 +32,6 @@ fn overview(c: &mut Criterion) {
});
});
- g.bench_function("construct/TinyStr", |b| {
- b.iter(|| {
- for s in STRINGS_4 {
- let _: TinyStr4 = black_box(s).parse().unwrap();
- let _: TinyStr8 = black_box(s).parse().unwrap();
- let _: TinyStr16 = black_box(s).parse().unwrap();
- }
- for s in STRINGS_8 {
- let _: TinyStr8 = black_box(s).parse().unwrap();
- let _: TinyStr16 = black_box(s).parse().unwrap();
- }
- for s in STRINGS_16 {
- let _: TinyStr16 = black_box(s).parse().unwrap();
- }
- });
- });
-
let parsed_ascii_4: Vec<TinyAsciiStr<4>> = STRINGS_4
.iter()
.map(|s| s.parse::<TinyAsciiStr<4>>().unwrap())
@@ -68,22 +48,6 @@ fn overview(c: &mut Criterion) {
.map(|s| s.parse::<TinyAsciiStr<16>>().unwrap())
.collect();
- let parsed_tiny_4: Vec<TinyStr4> = STRINGS_4
- .iter()
- .map(|s| s.parse::<TinyStr4>().unwrap())
- .collect();
- let parsed_tiny_8: Vec<TinyStr8> = STRINGS_4
- .iter()
- .chain(STRINGS_8)
- .map(|s| s.parse::<TinyStr8>().unwrap())
- .collect();
- let parsed_tiny_16: Vec<TinyStr16> = STRINGS_4
- .iter()
- .chain(STRINGS_8)
- .chain(STRINGS_16)
- .map(|s| s.parse::<TinyStr16>().unwrap())
- .collect();
-
g.bench_function("read/TinyAsciiStr", |b| {
b.iter(|| {
let mut collector: usize = 0;
@@ -103,25 +67,6 @@ fn overview(c: &mut Criterion) {
});
});
- g.bench_function("read/TinyStr", |b| {
- b.iter(|| {
- let mut collector: usize = 0;
- for t in black_box(&parsed_tiny_4) {
- let s: &str = t;
- collector += s.bytes().map(usize::from).sum::<usize>();
- }
- for t in black_box(&parsed_tiny_8) {
- let s: &str = t;
- collector += s.bytes().map(usize::from).sum::<usize>();
- }
- for t in black_box(&parsed_tiny_16) {
- let s: &str = t;
- collector += s.bytes().map(usize::from).sum::<usize>();
- }
- collector
- });
- });
-
g.bench_function("compare/TinyAsciiStr", |b| {
b.iter(|| {
let mut collector: usize = 0;
@@ -140,25 +85,6 @@ fn overview(c: &mut Criterion) {
collector
});
});
-
- g.bench_function("compare/TinyStr", |b| {
- b.iter(|| {
- let mut collector: usize = 0;
- for ts in black_box(&parsed_tiny_4).windows(2) {
- let o = ts[0].cmp(&ts[1]);
- collector ^= o as usize;
- }
- for ts in black_box(&parsed_tiny_8).windows(2) {
- let o = ts[0].cmp(&ts[1]);
- collector ^= o as usize;
- }
- for ts in black_box(&parsed_tiny_16).windows(2) {
- let o = ts[0].cmp(&ts[1]);
- collector ^= o as usize;
- }
- collector
- });
- });
}
criterion_group!(benches, overview,);
diff --git a/vendor/tinystr/src/ascii.rs b/vendor/tinystr/src/ascii.rs
index f39f39b73..9ab694f02 100644
--- a/vendor/tinystr/src/ascii.rs
+++ b/vendor/tinystr/src/ascii.rs
@@ -140,21 +140,23 @@ impl<const N: usize> TinyAsciiStr<N> {
pub const fn as_bytes(&self) -> &[u8] {
// Safe because `self.bytes.as_slice()` pointer-casts to `&[u8]`,
// and changing the length of that slice to self.len() < N is safe.
- unsafe { core::mem::transmute((self.bytes.as_slice().as_ptr(), self.len())) }
+ unsafe {
+ core::slice::from_raw_parts(self.bytes.as_slice().as_ptr() as *const u8, self.len())
+ }
}
#[inline]
#[must_use]
pub const fn all_bytes(&self) -> &[u8; N] {
// SAFETY: `self.bytes` has same size as [u8; N]
- unsafe { core::mem::transmute(&self.bytes) }
+ unsafe { &*(self.bytes.as_ptr() as *const [u8; N]) }
}
#[inline]
#[must_use]
- /// Resizes a TinyAsciiStr<N> to a TinyAsciiStr<M>.
+ /// Resizes a `TinyAsciiStr<N>` to a `TinyAsciiStr<M>`.
///
- /// If M < len() the string gets truncated, otherwise only the
+ /// If `M < len()` the string gets truncated, otherwise only the
/// memory representation changes.
pub const fn resize<const M: usize>(self) -> TinyAsciiStr<M> {
let mut bytes = [0; M];
@@ -729,7 +731,7 @@ mod test {
};
let expected = reference_f(&s);
let actual = tinystr_f(t);
- assert_eq!(expected, actual, "TinyAsciiStr<{}>: {:?}", N, s);
+ assert_eq!(expected, actual, "TinyAsciiStr<{N}>: {s:?}");
}
}
diff --git a/vendor/tinystr/src/databake.rs b/vendor/tinystr/src/databake.rs
index e10c194f8..0b127f97c 100644
--- a/vendor/tinystr/src/databake.rs
+++ b/vendor/tinystr/src/databake.rs
@@ -3,6 +3,7 @@
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
use crate::TinyAsciiStr;
+use crate::UnvalidatedTinyAsciiStr;
use databake::*;
impl<const N: usize> Bake for TinyAsciiStr<N> {
@@ -10,7 +11,27 @@ impl<const N: usize> Bake for TinyAsciiStr<N> {
env.insert("tinystr");
let string = self.as_str();
quote! {
- ::tinystr::tinystr!(#N, #string)
+ tinystr::tinystr!(#N, #string)
+ }
+ }
+}
+
+impl<const N: usize> databake::Bake for UnvalidatedTinyAsciiStr<N> {
+ fn bake(&self, env: &databake::CrateEnv) -> databake::TokenStream {
+ match self.try_into_tinystr() {
+ Ok(tiny) => {
+ let tiny = tiny.bake(env);
+ databake::quote! {
+ #tiny.to_unvalidated()
+ }
+ }
+ Err(_) => {
+ let bytes = self.0.bake(env);
+ env.insert("tinystr");
+ databake::quote! {
+ tinystr::UnvalidatedTinyAsciiStr::from_bytes_unchecked(*#bytes)
+ }
+ }
}
}
}
@@ -19,3 +40,9 @@ impl<const N: usize> Bake for TinyAsciiStr<N> {
fn test() {
test_bake!(TinyAsciiStr<10>, const: crate::tinystr!(10usize, "foo"), tinystr);
}
+
+#[test]
+fn test_unvalidated() {
+ test_bake!(UnvalidatedTinyAsciiStr<10>, const: crate::tinystr!(10usize, "foo").to_unvalidated(), tinystr);
+ test_bake!(UnvalidatedTinyAsciiStr<3>, const: crate::UnvalidatedTinyAsciiStr::from_bytes_unchecked(*b"AB\xCD"), tinystr);
+}
diff --git a/vendor/tinystr/src/lib.rs b/vendor/tinystr/src/lib.rs
index 7745da0e5..3d13e95ea 100644
--- a/vendor/tinystr/src/lib.rs
+++ b/vendor/tinystr/src/lib.rs
@@ -72,6 +72,7 @@ mod ascii;
mod asciibyte;
mod error;
mod int_ops;
+mod unvalidated;
#[cfg(feature = "serde")]
mod serde;
@@ -87,6 +88,7 @@ extern crate alloc;
pub use ascii::TinyAsciiStr;
pub use error::TinyStrError;
+pub use unvalidated::UnvalidatedTinyAsciiStr;
/// These are temporary compatability reexports that will be removed
/// in a future version.
diff --git a/vendor/tinystr/src/serde.rs b/vendor/tinystr/src/serde.rs
index 933491f17..4c3f8be13 100644
--- a/vendor/tinystr/src/serde.rs
+++ b/vendor/tinystr/src/serde.rs
@@ -46,7 +46,7 @@ impl<'de, const N: usize> Visitor<'de> for TinyAsciiStrVisitor<N> {
type Value = TinyAsciiStr<N>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
- write!(formatter, "a TinyAsciiStr<{}>", N)
+ write!(formatter, "a TinyAsciiStr<{N}>")
}
#[inline]
diff --git a/vendor/tinystr/src/ule.rs b/vendor/tinystr/src/ule.rs
index 0fa212095..eda43890b 100644
--- a/vendor/tinystr/src/ule.rs
+++ b/vendor/tinystr/src/ule.rs
@@ -2,20 +2,20 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
-use crate::TinyAsciiStr;
+use crate::{TinyAsciiStr, UnvalidatedTinyAsciiStr};
use zerovec::maps::ZeroMapKV;
use zerovec::ule::*;
use zerovec::{ZeroSlice, ZeroVec};
// Safety (based on the safety checklist on the ULE trait):
-// 1. CharULE does not include any uninitialized or padding bytes.
+// 1. TinyAsciiStr does not include any uninitialized or padding bytes.
// (achieved by `#[repr(transparent)]` on a type that satisfies this invariant)
-// 2. CharULE is aligned to 1 byte.
+// 2. TinyAsciiStr is aligned to 1 byte.
// (achieved by `#[repr(transparent)]` on a type that satisfies this invariant)
// 3. The impl of validate_byte_slice() returns an error if any byte is not valid.
// 4. The impl of validate_byte_slice() returns an error if there are extra bytes.
// 5. The other ULE methods use the default impl.
-// 6. CharULE byte equality is semantic equality
+// 6. TinyAsciiStr byte equality is semantic equality
unsafe impl<const N: usize> ULE for TinyAsciiStr<N> {
#[inline]
fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError> {
@@ -52,6 +52,46 @@ impl<'a, const N: usize> ZeroMapKV<'a> for TinyAsciiStr<N> {
type OwnedType = TinyAsciiStr<N>;
}
+// Safety (based on the safety checklist on the ULE trait):
+// 1. UnvalidatedTinyAsciiStr does not include any uninitialized or padding bytes.
+// (achieved by `#[repr(transparent)]` on a type that satisfies this invariant)
+// 2. UnvalidatedTinyAsciiStr is aligned to 1 byte.
+// (achieved by `#[repr(transparent)]` on a type that satisfies this invariant)
+// 3. The impl of validate_byte_slice() returns an error if any byte is not valid.
+// 4. The impl of validate_byte_slice() returns an error if there are extra bytes.
+// 5. The other ULE methods use the default impl.
+// 6. UnvalidatedTinyAsciiStr byte equality is semantic equality
+unsafe impl<const N: usize> ULE for UnvalidatedTinyAsciiStr<N> {
+ #[inline]
+ fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError> {
+ if bytes.len() % N != 0 {
+ return Err(ZeroVecError::length::<Self>(bytes.len()));
+ }
+ Ok(())
+ }
+}
+
+impl<const N: usize> AsULE for UnvalidatedTinyAsciiStr<N> {
+ type ULE = Self;
+
+ #[inline]
+ fn to_unaligned(self) -> Self::ULE {
+ self
+ }
+
+ #[inline]
+ fn from_unaligned(unaligned: Self::ULE) -> Self {
+ unaligned
+ }
+}
+
+impl<'a, const N: usize> ZeroMapKV<'a> for UnvalidatedTinyAsciiStr<N> {
+ type Container = ZeroVec<'a, UnvalidatedTinyAsciiStr<N>>;
+ type Slice = ZeroSlice<UnvalidatedTinyAsciiStr<N>>;
+ type GetType = UnvalidatedTinyAsciiStr<N>;
+ type OwnedType = UnvalidatedTinyAsciiStr<N>;
+}
+
#[cfg(test)]
mod test {
use crate::*;
diff --git a/vendor/tinystr/src/unvalidated.rs b/vendor/tinystr/src/unvalidated.rs
new file mode 100644
index 000000000..2fffbbc11
--- /dev/null
+++ b/vendor/tinystr/src/unvalidated.rs
@@ -0,0 +1,104 @@
+// This file is part of ICU4X. For terms of use, please see the file
+// called LICENSE at the top level of the ICU4X source tree
+// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
+
+use crate::TinyAsciiStr;
+use crate::TinyStrError;
+
+/// A fixed-length bytes array that is expected to be an ASCII string but does not enforce that invariant.
+///
+/// Use this type instead of `TinyAsciiStr` if you don't need to enforce ASCII during deserialization. For
+/// example, strings that are keys of a map don't need to ever be reified as `TinyAsciiStr`s.
+///
+/// The main advantage of this type over `[u8; N]` is that it serializes as a string in
+/// human-readable formats like JSON.
+#[derive(Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy)]
+pub struct UnvalidatedTinyAsciiStr<const N: usize>(pub(crate) [u8; N]);
+
+impl<const N: usize> UnvalidatedTinyAsciiStr<N> {
+ #[inline]
+ // Converts into a [`TinyAsciiStr`]. Fails if the bytes are not valid ASCII.
+ pub fn try_into_tinystr(&self) -> Result<TinyAsciiStr<N>, TinyStrError> {
+ TinyAsciiStr::try_from_raw(self.0)
+ }
+
+ #[doc(hidden)]
+ pub const fn from_bytes_unchecked(bytes: [u8; N]) -> Self {
+ Self(bytes)
+ }
+}
+
+impl<const N: usize> TinyAsciiStr<N> {
+ #[inline]
+ // Converts into a [`UnvalidatedTinyAsciiStr`]
+ pub const fn to_unvalidated(self) -> UnvalidatedTinyAsciiStr<N> {
+ UnvalidatedTinyAsciiStr(*self.all_bytes())
+ }
+}
+
+#[cfg(feature = "serde")]
+impl<const N: usize> serde::Serialize for UnvalidatedTinyAsciiStr<N> {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: serde::Serializer,
+ {
+ use serde::ser::Error;
+ self.try_into_tinystr()
+ .map_err(|_| S::Error::custom("invalid ascii in UnvalidatedTinyAsciiStr"))?
+ .serialize(serializer)
+ }
+}
+
+macro_rules! deserialize {
+ ($size:literal) => {
+ #[cfg(feature = "serde")]
+ impl<'de, 'a> serde::Deserialize<'de> for UnvalidatedTinyAsciiStr<$size>
+ where
+ 'de: 'a,
+ {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: serde::Deserializer<'de>,
+ {
+ if deserializer.is_human_readable() {
+ Ok(TinyAsciiStr::deserialize(deserializer)?.to_unvalidated())
+ } else {
+ Ok(Self(<[u8; $size]>::deserialize(deserializer)?))
+ }
+ }
+ }
+ };
+}
+
+deserialize!(1);
+deserialize!(2);
+deserialize!(3);
+deserialize!(4);
+deserialize!(5);
+deserialize!(6);
+deserialize!(7);
+deserialize!(8);
+deserialize!(9);
+deserialize!(10);
+deserialize!(11);
+deserialize!(12);
+deserialize!(13);
+deserialize!(14);
+deserialize!(15);
+deserialize!(16);
+deserialize!(17);
+deserialize!(18);
+deserialize!(19);
+deserialize!(20);
+deserialize!(21);
+deserialize!(22);
+deserialize!(23);
+deserialize!(24);
+deserialize!(25);
+deserialize!(26);
+deserialize!(27);
+deserialize!(28);
+deserialize!(29);
+deserialize!(30);
+deserialize!(31);
+deserialize!(32);