Struct icu_provider::prelude::DataKey
source · [−]pub struct DataKey { /* 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 DataKey
instances to produce optimized data files.
Therefore, users should not generally create DataKey instances; they should instead use
the ones exported by a component.
DataKey
s are created with the data_key!
macro:
const K: DataKey = icu_provider::data_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 data_key!
uses const
).
const K: DataKey = icu_provider::data_key!("foo/../bar@1");
Implementations
sourceimpl DataKey
impl DataKey
sourcepub const fn path(self) -> DataKeyPath
pub const fn path(self) -> DataKeyPath
Gets a human-readable representation of a DataKey
.
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.
sourcepub const fn hashed(self) -> DataKeyHash
pub const fn hashed(self) -> DataKeyHash
Gets a platform-independent hash of a DataKey
.
The hash is 4 bytes and allows for fast key comparison.
Example
use icu_provider::DataKey;
use icu_provider::DataKeyHash;
const KEY: DataKey = icu_provider::data_key!("foo@1");
const KEY_HASH: DataKeyHash = KEY.hashed();
assert_eq!(KEY_HASH.to_bytes(), [0xe2, 0xb6, 0x17, 0x71]);
sourcepub const fn metadata(self) -> DataKeyMetadata
pub const fn metadata(self) -> DataKeyMetadata
Gets the metadata associated with this DataKey
.
sourcepub const fn from_path_and_metadata(
path: DataKeyPath,
metadata: DataKeyMetadata
) -> Self
pub const fn from_path_and_metadata(
path: DataKeyPath,
metadata: DataKeyMetadata
) -> Self
sourcepub fn match_key(self, key: Self) -> Result<(), DataError>
pub fn match_key(self, key: Self) -> Result<(), DataError>
Returns Ok
if this data key matches the argument, or the appropriate error.
Convenience method for data providers that support a single DataKey
.
Examples
use icu_provider::prelude::*;
const FOO_BAR: DataKey = icu_provider::data_key!("foo/bar@1");
const FOO_BAZ: DataKey = icu_provider::data_key!("foo/baz@1");
const BAR_BAZ: DataKey = icu_provider::data_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::MissingDataKey,
..
})
));
assert!(matches!(
FOO_BAR.match_key(BAR_BAZ),
Err(DataError {
kind: DataErrorKind::MissingDataKey,
..
})
));
// The error context contains the argument:
assert_eq!(FOO_BAR.match_key(BAR_BAZ).unwrap_err().key, Some(BAR_BAZ));
Trait Implementations
sourceimpl Display for DataKey
impl Display for DataKey
This trait is implemented for compatibility with fmt!
.
To create a string, Writeable::write_to_string
is usually more efficient.
sourceimpl Ord for DataKey
impl Ord for DataKey
sourceimpl PartialOrd<DataKey> for DataKey
impl PartialOrd<DataKey> for DataKey
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Writeable for DataKey
impl Writeable for DataKey
sourcefn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
Writes a string 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
sourcefn writeable_length_hint(&self) -> LengthHint
fn writeable_length_hint(&self) -> LengthHint
Returns a hint for the number of UTF-8 bytes that will be written to the sink. Read more
sourcefn write_to_string(&self) -> Cow<'_, str>
fn write_to_string(&self) -> Cow<'_, str>
Creates a new String
with the data from this Writeable
. Like ToString
,
but smaller and faster. Read more
sourcefn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error> where
S: PartsWrite + ?Sized,
fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error> where
S: PartsWrite + ?Sized,
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
impl Copy for DataKey
impl Eq for DataKey
Auto Trait Implementations
impl RefUnwindSafe for DataKey
impl Send for DataKey
impl Sync for DataKey
impl Unpin for DataKey
impl UnwindSafe for DataKey
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Separable for T where
T: Display,
impl<T> Separable for T where
T: Display,
sourcefn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
Adds separators according to the given SeparatorPolicy
. Read more
sourcefn separate_with_commas(&self) -> String
fn separate_with_commas(&self) -> String
Inserts a comma every three digits from the right. Read more
sourcefn separate_with_spaces(&self) -> String
fn separate_with_spaces(&self) -> String
Inserts a space every three digits from the right. Read more
sourcefn separate_with_dots(&self) -> String
fn separate_with_dots(&self) -> String
Inserts a period every three digits from the right. Read more
sourcefn separate_with_underscores(&self) -> String
fn separate_with_underscores(&self) -> String
Inserts an underscore every three digits from the right. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more