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.

ResourceKeys 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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Create a DataRequest to a particular ResourceKey with default options.

Performs the conversion.

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Creates a filterable data provider with the given name for debugging. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.