Struct icu_provider::prelude::ResourceKey
source · [−]pub struct ResourceKey { /* private fields */ }
Expand description
Used for loading data from an ICU4X data provider.
A resource key is tightly coupled with the code that uses it to load data at runtime.
Executables can be searched for ResourceKey
instances to produce optimized data files.
Therefore, users should not generally create ResourceKey instances; they should instead use
the ones exported by a component.
ResourceKey
s are created with the resource_key!
macro:
const K: ResourceKey = icu_provider::resource_key!("foo/bar@1");
The human-readable path string ends with @
followed by one or more digits (the version
number). Paths do not contain characters other than ASCII letters and digits, _
, /
, =
.
Invalid paths are compile-time errors (as resource_key!
uses const
).
const K: ResourceKey = icu_provider::resource_key!("foo/../bar@1");
Implementations
Gets a human-readable representation of a ResourceKey
.
The human-readable path string ends with @
followed by one or more digits (the version
number). Paths do not contain characters other than ASCII letters and digits, _
, /
, =
.
Useful for reading and writing data to a file system.
Gets a machine-readable representation of a ResourceKey
.
The machine-readable hash is 4 bytes and can be used as the key in a map.
The hash is a 32-bit FxHash of the path, computed as if on a little-endian platform.
Returns Ok
if this data key matches the argument, or the appropriate error.
Convenience method for data providers that support a single ResourceKey
.
Examples
use icu_provider::prelude::*;
const FOO_BAR: ResourceKey = icu_provider::resource_key!("foo/bar@1");
const FOO_BAZ: ResourceKey = icu_provider::resource_key!("foo/baz@1");
const BAR_BAZ: ResourceKey = icu_provider::resource_key!("bar/baz@1");
assert!(matches!(
FOO_BAR.match_key(FOO_BAR),
Ok(())
));
assert!(matches!(
FOO_BAR.match_key(FOO_BAZ),
Err(DataError { kind: DataErrorKind::MissingResourceKey, .. })
));
assert!(matches!(
FOO_BAR.match_key(BAR_BAZ),
Err(DataError { kind: DataErrorKind::MissingResourceKey, .. })
));
// The error context contains the argument:
assert_eq!(
FOO_BAR.match_key(BAR_BAZ).unwrap_err().key,
Some(BAR_BAZ)
);
Trait Implementations
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Writes bytes to the given sink. Errors from the sink are bubbled up. The default implementation delegates to write_to_parts, and discards any Part annotations. Read more
Returns a hint for the number of bytes that will be written to the sink. Read more
Creates a new String with the data from this Writeable. Like ToString, but smaller and faster. Read more
Write bytes and Part annotations to the given sink. Errors from the sink are bubbled up. The default implementation delegates to write_to, and doesn’t produce any Part annotations. Read more
Auto Trait Implementations
impl RefUnwindSafe for ResourceKey
impl Send for ResourceKey
impl Sync for ResourceKey
impl Unpin for ResourceKey
impl UnwindSafe for ResourceKey
Blanket Implementations
Mutably borrows from an owned value. Read more
fn filterable(
self,
filter_name: &'static str
) -> RequestFilterDataProvider<Self, fn(_: &DataRequest) -> bool>
fn filterable(
self,
filter_name: &'static str
) -> RequestFilterDataProvider<Self, fn(_: &DataRequest) -> bool>
Creates a filterable data provider with the given name for debugging. Read more