Add rustc_baked_icu_data crate.

This commit is contained in:
Charles Lew 2022-11-05 13:09:13 +08:00 committed by Manish Goregaokar
parent 70fe5f08ff
commit 42d3bda08c
7 changed files with 1243 additions and 0 deletions

View File

@ -0,0 +1,9 @@
[package]
name = "rustc_baked_icu_data"
version = "0.0.0"
edition = "2021"
[dependencies]
icu_list = "1.0.0"
icu_provider = "1.0.1"
litemap = "0.6.0"

View File

@ -0,0 +1,18 @@
// @generated
impl AnyProvider for BakedDataProvider {
fn load_any(&self, key: DataKey, req: DataRequest) -> Result<AnyResponse, DataError> {
const ANDLISTV1MARKER: ::icu_provider::DataKeyHash =
::icu_list::provider::AndListV1Marker::KEY.hashed();
#[allow(clippy::match_single_binding)]
match key.hashed() {
ANDLISTV1MARKER => list::and_v1::DATA
.get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse())
.copied()
.map(AnyPayload::from_static_ref)
.ok_or(DataErrorKind::MissingLocale),
_ => Err(DataErrorKind::MissingDataKey),
}
.map_err(|e| e.with_req(key, req))
.map(|payload| AnyResponse { payload: Some(payload), metadata: Default::default() })
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,2 @@
// @generated
pub mod and_v1;

View File

@ -0,0 +1,25 @@
// @generated
mod list;
/// This data provider was programmatically generated by [`icu_datagen`](
/// https://unicode-org.github.io/icu4x-docs/doc/icu_datagen/enum.Out.html#variant.Module).
#[non_exhaustive]
pub struct BakedDataProvider;
use ::icu_provider::prelude::*;
impl DataProvider<::icu_list::provider::AndListV1Marker> for BakedDataProvider {
fn load(
&self,
req: DataRequest,
) -> Result<DataResponse<::icu_list::provider::AndListV1Marker>, DataError> {
Ok(DataResponse {
metadata: Default::default(),
payload: Some(DataPayload::from_owned(zerofrom::ZeroFrom::zero_from(
*list::and_v1::DATA
.get_by(|k| req.locale.strict_cmp(k.as_bytes()).reverse())
.ok_or_else(|| {
DataErrorKind::MissingLocale
.with_req(::icu_list::provider::AndListV1Marker::KEY, req)
})?,
))),
})
}
}

View File

@ -0,0 +1,17 @@
//! Baked ICU data for eager translation support.
//!
#![allow(elided_lifetimes_in_paths)]
// generated with:
// ```text
// icu4x-datagen -W --pretty --fingerprint --use-separate-crates --cldr-tag latest --icuexport-tag latest \
// --format mod -l en es fr it ja pt ru tr zh-Hans zh-Hant -k list/and@1 -o src/data
// ```
mod data;
pub use data::BakedDataProvider;
pub fn baked_data_provider() -> BakedDataProvider {
data::BakedDataProvider
}

View File

@ -133,6 +133,10 @@
"hashbrown",
"hermit-abi",
"humantime",
"icu_list",
"icu_locid",
"icu_provider",
"icu_provider_macros",
"if_chain",
"indexmap",
"instant",
@ -145,6 +149,7 @@
"libc",
"libloading",
"libz-sys",
"litemap",
"lock_api",
"log",
"matchers",
@ -253,9 +258,16 @@
"winapi-i686-pc-windows-gnu",
"winapi-util",
"winapi-x86_64-pc-windows-gnu",
"writeable",
// this is a false-positive: it's only used by rustfmt, but because it's enabled through a
// feature, tidy thinks it's used by rustc as well.
"yansi-term",
"yoke",
"yoke-derive",
"zerofrom",
"zerofrom-derive",
"zerovec",
"zerovec-derive",
];
const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[