Skip to content

Commit

Permalink
Re-write ResourceKey (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Jan 19, 2022
1 parent 55f95e1 commit 26089b2
Show file tree
Hide file tree
Showing 20 changed files with 280 additions and 256 deletions.
5 changes: 1 addition & 4 deletions provider/cldr/src/transform/decimal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ impl TryFrom<&dyn CldrPaths> for NumbersProvider {

impl KeyedDataProvider for NumbersProvider {
fn supports_key(resc_key: &ResourceKey) -> Result<(), DataError> {
if resc_key.category != ResourceCategory::Decimal || resc_key.version != 1 {
return Err(DataErrorKind::MissingResourceKey.with_key(*resc_key));
}
Ok(())
resc_key.match_key(key::SYMBOLS_V1)
}
}

Expand Down
8 changes: 5 additions & 3 deletions provider/cldr/src/transform/plurals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ impl TryFrom<&dyn CldrPaths> for PluralsProvider {

impl KeyedDataProvider for PluralsProvider {
fn supports_key(resc_key: &ResourceKey) -> Result<(), DataError> {
if resc_key.category != ResourceCategory::Plurals || resc_key.version != 1 {
return Err(DataErrorKind::MissingResourceKey.with_key(*resc_key));
// TODO(#442): Clean up KeyedDataProvider
match *resc_key {
key::CARDINAL_V1 => Ok(()),
key::ORDINAL_V1 => Ok(()),
_ => Err(DataErrorKind::MissingResourceKey.with_key(*resc_key)),
}
Ok(())
}
}

Expand Down
12 changes: 9 additions & 3 deletions provider/cldr/src/transform/time_zones/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ impl TryFrom<&str> for TimeZonesProvider {

impl KeyedDataProvider for TimeZonesProvider {
fn supports_key(resc_key: &ResourceKey) -> Result<(), DataError> {
if resc_key.category != ResourceCategory::TimeZone || resc_key.version != 1 {
return Err(DataErrorKind::MissingResourceKey.with_key(*resc_key));
// TODO(#442): Clean up KeyedDataProvider
match *resc_key {
key::TIMEZONE_FORMATS_V1 => Ok(()),
key::TIMEZONE_EXEMPLAR_CITIES_V1 => Ok(()),
key::TIMEZONE_GENERIC_NAMES_LONG_V1 => Ok(()),
key::TIMEZONE_GENERIC_NAMES_SHORT_V1 => Ok(()),
key::TIMEZONE_SPECIFIC_NAMES_LONG_V1 => Ok(()),
key::TIMEZONE_SPECIFIC_NAMES_SHORT_V1 => Ok(()),
_ => Err(DataErrorKind::MissingResourceKey.with_key(*resc_key)),
}
Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion provider/core/src/data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl DataRequest {
/// ```
/// use icu_provider::prelude::*;
///
/// const FOO_BAR: ResourceKey = icu_provider::resource_key!(x, "foo", "bar", 1);
/// const FOO_BAR: ResourceKey = icu_provider::resource_key!("foo/bar@1");
///
/// let req_no_langid = DataRequest {
/// resource_path: ResourcePath {
Expand Down
2 changes: 1 addition & 1 deletion provider/core/src/data_provider/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::yoke;
// JSON string. It also exercises most of the data provider code paths.

/// Key for HelloAlt, used for testing mismatched types
const HELLO_ALT_KEY: ResourceKey = crate::resource_key!(Core, "helloalt", 1);
const HELLO_ALT_KEY: ResourceKey = crate::resource_key!("core/helloalt@1");

/// A data struct serialization-compatible with HelloWorldV1 used for testing mismatched types
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Yokeable, ZeroCopyFrom)]
Expand Down
2 changes: 1 addition & 1 deletion provider/core/src/dynutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
/// use icu_provider::prelude::*;
/// use icu_provider::marker::CowStrMarker;
/// use std::borrow::Cow;
/// const DEMO_KEY: ResourceKey = icu_provider::resource_key!(x, "foo", "bar", 1);
/// const DEMO_KEY: ResourceKey = icu_provider::resource_key!("foo/bar@1");
///
/// // A small DataProvider that returns owned strings
/// struct MyProvider(pub String);
Expand Down
3 changes: 1 addition & 2 deletions provider/core/src/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use litemap::LiteMap;

pub mod key {
use crate::resource::ResourceKey;
use crate::resource_key;
pub const HELLO_WORLD_V1: ResourceKey = resource_key!(Core, "helloworld", 1);
pub const HELLO_WORLD_V1: ResourceKey = crate::resource_key!("core/helloworld@1");
}

/// A struct containing "Hello World" in the requested language.
Expand Down
1 change: 0 additions & 1 deletion provider/core/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ fn test_escape_for_json() {
/// 4. FxHash is designed to output 32-bit or 64-bit values, whereas SHA outputs more bits,
/// such that truncation would be required in order to fit into a u32, partially reducing
/// the benefit of a cryptographically secure algorithm
#[allow(dead_code)]
pub const fn fxhash_32(bytes: &[u8]) -> u32 {
// This code is adapted from https://github.com/rust-lang/rustc-hash,
// whose license text is reproduced below.
Expand Down
9 changes: 0 additions & 9 deletions provider/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ pub mod prelude {
pub use crate::error::DataError;
pub use crate::error::DataErrorKind;
pub use crate::marker::DataMarker;
pub use crate::resource::ResourceCategory;
pub use crate::resource::ResourceKey;
pub use crate::resource::ResourceOptions;
pub use crate::resource::ResourcePath;
Expand All @@ -164,11 +163,3 @@ pub use yoke;

// Also include the same symbols at the top level for selective inclusion
pub use prelude::*;

pub mod internal {
//! Macro dependencies; not intended to be used directly.
/// Re-export tinystr16 for macro resource_key!()
pub use tinystr::tinystr16;
/// Re-export tinystr4 for macro resource_key!()
pub use tinystr::tinystr4;
}
Loading

0 comments on commit 26089b2

Please sign in to comment.