icu_properties::provider::names

Struct NormalizedPropertyNameStr

Source
pub struct NormalizedPropertyNameStr(/* private fields */);
Expand description

This is a property name that can be “loose matched” as according to PropertyValueAliases.txt

(matched case-insensitively in ASCII, ignoring underscores, whitespace, and hyphens)

This is expected to be ASCII, but we do not rely on this invariant anywhere except during datagen.

The Ord impl will sort things using strict equality, but in such a way that all loose-equal items will sort into the same area, such that a map can be searched for both strict and loose equality.

🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, including in SemVer minor releases. While the serde representation of data structs is guaranteed to be stable, their Rust representation might not be. Use with caution.

§Examples

Using a NormalizedPropertyNameStr as the key of a ZeroMap:

use icu::properties::provider::names::NormalizedPropertyNameStr;
use zerovec::ZeroMap;

let map: ZeroMap<NormalizedPropertyNameStr, usize> = [
    (NormalizedPropertyNameStr::from_str("A_BC"), 11),
    (NormalizedPropertyNameStr::from_str("dEf"), 22),
    (NormalizedPropertyNameStr::from_str("G_H-I"), 33),
]
.into_iter()
.collect();

let key_approx = NormalizedPropertyNameStr::from_str("AB-C");
let key_exact = NormalizedPropertyNameStr::from_str("A_BC");

// Strict lookup:
assert_eq!(None, map.get_copied(key_approx));
assert_eq!(Some(11), map.get_copied(key_exact));

// Loose lookup:
assert_eq!(Some(11), map.get_copied_by(|u| u.cmp_loose(key_approx)));
assert_eq!(Some(11), map.get_copied_by(|u| u.cmp_loose(key_exact)));

Implementations§

Source§

impl NormalizedPropertyNameStr

Source

pub fn cmp_loose(&self, other: &Self) -> Ordering

Perform the loose comparison as defined in NormalizedPropertyNameStr.

Source

pub const fn from_str(s: &str) -> &Self

Convert a string reference to a NormalizedPropertyNameStr.

Source

pub const fn cast_ref(value: &UnvalidatedStr) -> &Self

Convert a UnvalidatedStr reference to a NormalizedPropertyNameStr reference.

Source

pub const fn cast_box(value: Box<UnvalidatedStr>) -> Box<Self>

Convert a UnvalidatedStr box to a NormalizedPropertyNameStr box.

Source

pub fn boxed_from_bytes(b: &[u8]) -> Box<Self>

Get a NormalizedPropertyNameStr box from a byte slice.

Trait Implementations§

Source§

impl Debug for NormalizedPropertyNameStr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for NormalizedPropertyNameStr

The Ord impl will sort things using strict equality, but in such a way that all loose-equal items will sort into the same area, such that a map can be searched for both strict and loose equality.

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq for NormalizedPropertyNameStr

Source§

fn eq(&self, other: &NormalizedPropertyNameStr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for NormalizedPropertyNameStr

The Ord/PartialOrd impl will sort things using strict equality, but in such a way that all loose-equal items will sort into the same area, such that a map can be searched for both strict and loose equality.

Source§

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 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl VarULE for NormalizedPropertyNameStr

Source§

fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>

Validates a byte slice, &[u8]. Read more
Source§

unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &Self

Takes a byte slice, &[u8], and return it as &Self with the same lifetime, assuming that this byte slice has previously been run through Self::parse_byte_slice() with success. Read more
Source§

fn parse_byte_slice(bytes: &[u8]) -> Result<&Self, ZeroVecError>

Parses a byte slice, &[u8], and return it as &Self with the same lifetime. Read more
Source§

fn as_byte_slice(&self) -> &[u8]

Given &Self, returns a &[u8] with the same lifetime. Read more
Source§

fn to_boxed(&self) -> Box<Self>

Allocate on the heap as a Box<T>
Source§

impl<'a> ZeroMapKV<'a> for NormalizedPropertyNameStr

Source§

type Container = VarZeroVec<'a, NormalizedPropertyNameStr>

The container that can be used with this type: ZeroVec or VarZeroVec.
Source§

type Slice = VarZeroSlice<NormalizedPropertyNameStr>

Source§

type GetType = NormalizedPropertyNameStr

The type produced by Container::get() Read more
Source§

type OwnedType = Box<NormalizedPropertyNameStr>

The type produced by Container::replace() and Container::remove(), also used during deserialization. If Self is human readable serialized, deserializing to Self::OwnedType should produce the same value once passed through Self::owned_as_self() Read more
Source§

impl Eq for NormalizedPropertyNameStr

Source§

impl StructuralPartialEq for NormalizedPropertyNameStr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> EncodeAsVarULE<T> for T
where T: VarULE + ?Sized,

Source§

fn encode_var_ule_as_slices<R>(&self, cb: impl FnOnce(&[&[u8]]) -> R) -> R

Calls cb with a piecewise list of byte slices that when concatenated produce the memory pattern of the corresponding instance of T. Read more
Source§

fn encode_var_ule_len(&self) -> usize

Return the length, in bytes, of the corresponding VarULE type
Source§

fn encode_var_ule_write(&self, dst: &mut [u8])

Write the corresponding VarULE type to the dst buffer. dst should be the size of Self::encode_var_ule_len()