Struct icu::properties::PropertyParser
source · pub struct PropertyParser<T> { /* private fields */ }
Expand description
A struct capable of looking up a property value from a string name.
Access its data by calling Self::as_borrowed()
and using the methods on
PropertyParserBorrowed
.
The name can be a short name (Lu
), a long name(Uppercase_Letter
),
or an alias.
Property names can be looked up using “strict” matching (looking for a name that matches exactly), or “loose matching”, where the name is allowed to deviate in terms of ASCII casing, whitespace, underscores, and hyphens.
§Example
use icu::properties::props::GeneralCategory;
use icu::properties::PropertyParser;
let lookup = PropertyParser::<GeneralCategory>::new();
// short name for value
assert_eq!(
lookup.get_strict("Lu"),
Some(GeneralCategory::UppercaseLetter)
);
assert_eq!(
lookup.get_strict("Pd"),
Some(GeneralCategory::DashPunctuation)
);
// long name for value
assert_eq!(
lookup.get_strict("Uppercase_Letter"),
Some(GeneralCategory::UppercaseLetter)
);
assert_eq!(
lookup.get_strict("Dash_Punctuation"),
Some(GeneralCategory::DashPunctuation)
);
// name has incorrect casing
assert_eq!(lookup.get_strict("dashpunctuation"), None);
// loose matching of name
assert_eq!(
lookup.get_loose("dash-punctuation"),
Some(GeneralCategory::DashPunctuation)
);
// fake property
assert_eq!(lookup.get_strict("Animated_Gif"), None);
Implementations§
source§impl<T> PropertyParser<T>
impl<T> PropertyParser<T>
sourcepub fn new() -> PropertyParserBorrowed<'static, T>where
T: ParseableEnumeratedProperty,
pub fn new() -> PropertyParserBorrowed<'static, T>where
T: ParseableEnumeratedProperty,
Creates a new instance of PropertyParser<T>
using compiled data.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_unstable(
provider: &(impl DataProvider<<T as ParseableEnumeratedProperty>::DataMarker> + ?Sized),
) -> Result<PropertyParser<T>, DataError>where
T: ParseableEnumeratedProperty,
pub fn try_new_unstable(
provider: &(impl DataProvider<<T as ParseableEnumeratedProperty>::DataMarker> + ?Sized),
) -> Result<PropertyParser<T>, DataError>where
T: ParseableEnumeratedProperty,
A version of Self::new
that uses custom data provided by a DataProvider
.
sourcepub fn as_borrowed(&self) -> PropertyParserBorrowed<'_, T>
pub fn as_borrowed(&self) -> PropertyParserBorrowed<'_, T>
Construct a borrowed version of this type that can be queried.
This avoids a potential small underlying cost per API call (like get_strict()
) by consolidating it
up front.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for PropertyParser<T>
impl<T> RefUnwindSafe for PropertyParser<T>
impl<T> Send for PropertyParser<T>
impl<T> Sync for PropertyParser<T>
impl<T> Unpin for PropertyParser<T>
impl<T> UnwindSafe for PropertyParser<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more