#[repr(u8)]
#[non_exhaustive]
pub enum Strength {
    Primary,
    Secondary,
    Tertiary,
    Quaternary,
    Identical,
}
Expand description

The collation strength that indicates how many levels to compare. If an earlier level isn’t equal, the earlier level is decisive. If the result is equal on a level, but the strength is higher, the comparison proceeds to the next level.

Note: The bit layout of CollatorOptions requires Strength to fit in 3 bits.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Primary

Compare only on the level of base letters. This level corresponds to the ECMA-402 sensitivity “base”.

use icu_collator::*;

let mut options = CollatorOptions::new();
options.strength = Some(Strength::Primary);
let collator = Collator::try_new_unstable(
    &icu_testdata::unstable(),
    &Default::default(),
    options,
)
.unwrap();
assert_eq!(collator.compare("E", "é"), core::cmp::Ordering::Equal);
§

Secondary

Compare also on the secondary level, which corresponds to diacritics in scripts that use them. This level corresponds to the ECMA-402 sensitivity “accent”.

use icu_collator::*;

let mut options = CollatorOptions::new();
options.strength = Some(Strength::Secondary);
let collator = Collator::try_new_unstable(
    &icu_testdata::unstable(),
    &Default::default(),
    options,
)
.unwrap();
assert_eq!(collator.compare("E", "e"), core::cmp::Ordering::Equal);
assert_eq!(collator.compare("e", "é"), core::cmp::Ordering::Less);
assert_eq!(collator.compare("あ", "ア"), core::cmp::Ordering::Equal);
assert_eq!(collator.compare("ァ", "ア"), core::cmp::Ordering::Equal);
assert_eq!(collator.compare("ア", "ア"), core::cmp::Ordering::Equal);
§

Tertiary

Compare also on the tertiary level. By default, if the separate case level is disabled, this corresponds to case for bicameral scripts. This level distinguishes Hiragana and Katakana. This also captures other minor differences, such as half-width vs. full-width when the Japanese tailoring isn’t in use.

This is the default comparison level and appropriate for most scripts. This level corresponds to the ECMA-402 sensitivity “variant”.

use icu_collator::*;

let mut options = CollatorOptions::new();
options.strength = Some(Strength::Tertiary);
let collator =
  Collator::try_new_unstable(&icu_testdata::unstable(),
                    &Default::default(),
                    options).unwrap();
assert_eq!(collator.compare("E", "e"),
           core::cmp::Ordering::Greater);
assert_eq!(collator.compare("e", "é"),
           core::cmp::Ordering::Less);
assert_eq!(collator.compare("あ", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(collator.compare("ァ", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(collator.compare("ア", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(collator.compare("e", "e"), // Full-width e
           core::cmp::Ordering::Less);

let locale = icu_locid::locale!("ja");
let ja_collator =
  Collator::try_new_unstable(&icu_testdata::unstable(),
                    &locale.into(),
                    options).unwrap();
assert_eq!(ja_collator.compare("E", "e"),
           core::cmp::Ordering::Greater);
assert_eq!(ja_collator.compare("e", "é"),
           core::cmp::Ordering::Less);
assert_eq!(ja_collator.compare("あ", "ア"),
           core::cmp::Ordering::Equal); // Unlike root!
assert_eq!(ja_collator.compare("ァ", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(ja_collator.compare("ア", "ア"),
           core::cmp::Ordering::Equal); // Unlike root!
assert_eq!(ja_collator.compare("e", "e"), // Full-width e
           core::cmp::Ordering::Equal); // Unlike root!
§

Quaternary

Compare also on the quaternary level. For Japanese, Higana and Katakana are distinguished at the quaternary level. Also, if AlternateHandling::Shifted is used, the collation elements whose level gets shifted are shifted to this level.

use icu_collator::*;

let mut options = CollatorOptions::new();
options.strength = Some(Strength::Quaternary);

let ja_locale = icu_locid::locale!("ja");
let ja_collator =
  Collator::try_new_unstable(&icu_testdata::unstable(),
                    &ja_locale.into(),
                    options).unwrap();
assert_eq!(ja_collator.compare("あ", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(ja_collator.compare("ア", "ア"),
           core::cmp::Ordering::Equal);
assert_eq!(ja_collator.compare("e", "e"), // Full-width e
           core::cmp::Ordering::Equal);

// Even this level doesn't distinguish everything,
// e.g. Hebrew cantillation marks are still ignored.
let collator =
  Collator::try_new_unstable(&icu_testdata::unstable(),
                    &Default::default(),
                    options).unwrap();
assert_eq!(collator.compare("דחי", "דחי֭"),
           core::cmp::Ordering::Equal);

TODO: Thai example.

§

Identical

Compare the NFD form by code point order as the quinary level. This level makes the comparison slower and should not be used in the general case. However, it can be used to distinguish full-width and half-width forms when the Japanese tailoring is in use and to distinguish e.g. Hebrew cantillation markse. Use this level if you need JIS X 4061-1996 compliance for Japanese on the level of distinguishing full-width and half-width forms.

use icu_collator::*;

let mut options = CollatorOptions::new();
options.strength = Some(Strength::Identical);

let ja_locale = icu_locid::locale!("ja");
let ja_collator =
  Collator::try_new_unstable(&icu_testdata::unstable(),
                    &ja_locale.into(),
                    options).unwrap();
assert_eq!(ja_collator.compare("ア", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(ja_collator.compare("e", "e"), // Full-width e
           core::cmp::Ordering::Less);

let collator =
  Collator::try_new_unstable(&icu_testdata::unstable(),
                    &Default::default(),
                    options).unwrap();
assert_eq!(collator.compare("דחי", "דחי֭"),
           core::cmp::Ordering::Less);

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
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. 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

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. 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.