Skip to main content

CollatorBorrowed

Struct CollatorBorrowed 

Source
pub struct CollatorBorrowed<'a> {
    special_primaries: &'a CollationSpecialPrimariesValidated<'a>,
    root: &'a CollationData<'a>,
    tailoring: &'a CollationData<'a>,
    jamo: &'a CollationJamo<'a>,
    diacritics: &'a CollationDiacritics<'a>,
    options: CollatorOptionsBitField,
    reordering: Option<&'a CollationReordering<'a>>,
    decompositions: &'a DecompositionData<'a>,
    tables: &'a DecompositionTables<'a>,
    lithuanian_dot_above: bool,
}
Expand description

Compares strings according to culturally-relevant ordering, borrowed version.

Fields§

§special_primaries: &'a CollationSpecialPrimariesValidated<'a>§root: &'a CollationData<'a>§tailoring: &'a CollationData<'a>§jamo: &'a CollationJamo<'a>§diacritics: &'a CollationDiacritics<'a>§options: CollatorOptionsBitField§reordering: Option<&'a CollationReordering<'a>>§decompositions: &'a DecompositionData<'a>§tables: &'a DecompositionTables<'a>§lithuanian_dot_above: bool

Implementations§

Source§

impl CollatorBorrowed<'static>

Source

pub fn try_new( prefs: CollatorPreferences, options: CollatorOptions, ) -> Result<Self, DataError>

Creates a collator for the given locale and options from compiled data.

Source

pub const fn static_to_owned(self) -> Collator

Cheaply converts a CollatorBorrowed<'static> into a Collator.

Note: Due to branching and indirection, using Collator might inhibit some compile-time optimizations that are possible with CollatorBorrowed.

Source§

impl<'data> CollatorBorrowed<'data>

Source

pub fn resolved_options(&self) -> ResolvedCollatorOptions

The resolved options showing how the default options, the requested options, and the options from locale data were combined.

Source

fn norm_trie(&self) -> &'data FastCodePointTrie<'data, u32>

Source

pub fn compare(&self, left: &str, right: &str) -> Ordering

Compare guaranteed well-formed UTF-8 slices.

Source

pub fn compare_utf8(&self, left: &[u8], right: &[u8]) -> Ordering

Compare potentially ill-formed UTF-8 slices. Ill-formed input is compared as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard.

Source

pub fn compare_utf16(&self, left: &[u16], right: &[u16]) -> Ordering

Compare potentially ill-formed UTF-16 slices. Unpaired surrogates are compared as if each one was a REPLACEMENT CHARACTER.

Source

pub fn compare_latin1(&self, left: &[u8], right: &[u8]) -> Ordering

Compare Latin1 slices.

Enabled with the latin1 Cargo feature.

Source

pub fn compare_latin1_utf16(&self, left: &[u8], right: &[u16]) -> Ordering

Compare Latin1 slice with potentially ill-formed UTF-16 slice.

If you need to compare a potentially ill-formed UTF-16 slice with a Latin1 slice, swap the arguments and call reverse() on the return value.

Enabled with the latin1 Cargo feature.

Source

fn numeric_primary(&self) -> Option<u8>

Source

fn variable_top(&self) -> u32

Source

fn compare_impl<L, R, H, T>( &'data self, left_chars: L, right_chars: R, head_chars: H, variable_top: u32, ) -> Ordering
where L: Iterator<Item = (char, u32)> + WithTrie<'data, T, u32> + 'data, R: Iterator<Item = (char, u32)> + WithTrie<'data, T, u32> + 'data, H: DoubleEndedIterator<Item = (char, u32)> + 'data, T: AbstractCodePointTrie<'data, u32> + 'data,

The implementation of the comparison operation.

head_chars is an iterator backward over the identical prefix and left_chars and right_chars are iterators forward over the parts after the identical prefix.

Source

fn sort_key_levels(&self) -> u8

Source

pub fn write_sort_key_to<S>( &self, s: &str, sink: &mut S, ) -> Result<S::Output, S::Error>

Given valid UTF-8, write the sort key bytes up to the collator’s strength.

The bytes are written to an implementor of CollationKeySink, a no-std version of std::io::Write. This trait is currently unstable, but it is implemented by Vec<u8>, VecDeque<u8>, SmallVec<[u8; N]>, and &mut [u8] (returning an error if the slice is too small).

If two sort keys generated at the same strength are compared bytewise, the result is the same as a collation comparison of the original strings at that strength.

For identical strength, the UTF-8 NFD normalization is appended for breaking ties.

No terminating zero byte is written to the output, so the output is not a valid C string, but the caller may append a zero afterward if a C string is desired.

⚠️ Generating a sort key is expensive relative to comparison because to compare, the collator skips identical prefixes before doing more complex comparison. Only use sort keys if you expect to compare them many times so as to amortize the cost of generating them. Measurement of this performance trade-off would be a good idea.

⚠️ Sort keys, if stored durably, should be presumed to be invalidated by a CLDR update, a new version of Unicode, or an update to the ICU4X code. Applications using sort keys must be prepared to recompute them if required and should take the performance of such an operation into account when deciding to use sort keys.

⚠️ If you should store sort keys in a database that is or becomes so large that regenerating sort keys becomes impractical, you should not expect ICU4X to support your using an older, frozen copy of the sort key generation algorithm with a later version of the library.

§Example
use icu_collator::{
    options::{CollatorOptions, Strength},
    Collator,
};
use icu_locale::locale;
let locale = locale!("utf").into();
let mut options = CollatorOptions::default();
options.strength = Some(Strength::Primary);
let collator = Collator::try_new(locale, options).unwrap();

let mut k1 = Vec::new();
let Ok(()) = collator.write_sort_key_to("hello", &mut k1);
let mut k2 = Vec::new();
let Ok(()) = collator.write_sort_key_to("Héłłö", &mut k2);
assert_eq!(k1, k2);
Source

pub fn write_sort_key_utf8_to<S>( &self, s: &[u8], sink: &mut S, ) -> Result<S::Output, S::Error>

Given potentially invalid UTF-8, write the sort key bytes up to the collator’s strength.

For further details, see Self::write_sort_key_to.

Source

pub fn write_sort_key_utf16_to<S>( &self, s: &[u16], sink: &mut S, ) -> Result<S::Output, S::Error>

Given potentially invalid UTF-16, write the sort key bytes up to the collator’s strength.

For further details, see Self::write_sort_key_to.

Source

fn write_sort_key_impl<I, T, S>( &'data self, iter: I, sink: &mut S, ) -> Result<S::Output, S::Error>
where I: Iterator<Item = (char, u32)> + WithTrie<'data, T, u32> + Clone + 'data, T: AbstractCodePointTrie<'data, u32> + 'data, S: CollationKeySink + ?Sized, S::State: Default,

Source

fn write_sort_key_up_to_quaternary<I, S, T>( &'data self, iter: I, sink: &mut S, state: &mut S::State, ) -> Result<(), S::Error>
where I: Iterator<Item = (char, u32)> + WithTrie<'data, T, u32> + Clone + 'data, T: AbstractCodePointTrie<'data, u32> + 'data, S: CollationKeySink + ?Sized,

Write the sort key bytes up to the collator’s strength.

Optionally write the case level. Separate levels with the LEVEL_SEPARATOR_BYTE, but do not write a terminating zero as with a C string.

Trait Implementations§

Source§

impl<'a> Debug for CollatorBorrowed<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CollatorBorrowed<'a>

§

impl<'a> RefUnwindSafe for CollatorBorrowed<'a>

§

impl<'a> Send for CollatorBorrowed<'a>

§

impl<'a> Sync for CollatorBorrowed<'a>

§

impl<'a> Unpin for CollatorBorrowed<'a>

§

impl<'a> UnsafeUnpin for CollatorBorrowed<'a>

§

impl<'a> UnwindSafe for CollatorBorrowed<'a>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,