Struct CodePointTrie

struct CodePointTrie<'trie, T: TrieValue> { ... }

This struct represents a de-serialized CodePointTrie that was exported from ICU binary data.

For more information:

Implementations

impl<'trie, T: TrieValue> CodePointTrie<'trie, T>

fn try_new(header: CodePointTrieHeader, index: ZeroVec<'trie, u16>, data: ZeroVec<'trie, T>) -> Result<CodePointTrie<'trie, T>, Error>

Returns a new CodePointTrie backed by borrowed data for the index array and data array, whose data values have width W.

fn get32(self: &Self, code_point: u32) -> T

Returns the value that is associated with code_point in this CodePointTrie.

Examples

use icu::collections::codepointtrie::planes;
let trie = planes::get_planes_trie();

assert_eq!(0, trie.get32(0x41)); // 'A' as u32
assert_eq!(0, trie.get32(0x13E0)); // 'Ꮰ' as u32
assert_eq!(1, trie.get32(0x10044)); // '𐁄' as u32
fn get(self: &Self, c: char) -> T

Returns the value that is associated with char in this CodePointTrie.

Examples

use icu::collections::codepointtrie::planes;
let trie = planes::get_planes_trie();

assert_eq!(0, trie.get('A')); // 'A' as u32
assert_eq!(0, trie.get('')); // 'Ꮰ' as u32
assert_eq!(1, trie.get('𐁄')); // '𐁄' as u32
fn get32_ule(self: &Self, code_point: u32) -> Option<&<T as >::ULE>

Returns a reference to the ULE of the value that is associated with code_point in this CodePointTrie.

Examples

use icu::collections::codepointtrie::planes;
let trie = planes::get_planes_trie();

assert_eq!(Some(&0), trie.get32_ule(0x41)); // 'A' as u32
assert_eq!(Some(&0), trie.get32_ule(0x13E0)); // 'Ꮰ' as u32
assert_eq!(Some(&1), trie.get32_ule(0x10044)); // '𐁄' as u32
fn get_range(self: &Self, start: u32) -> Option<CodePointMapRange<T>>

Returns a CodePointMapRange struct which represents a range of code points associated with the same trie value. The returned range will be the longest stretch of consecutive code points starting at start that share this value.

This method is designed to use the internal details of the structure of CodePointTrie to be optimally efficient. This will outperform a naive approach that just uses [CodePointTrie::get()].

This method provides lower-level functionality that can be used in the implementation of other methods that are more convenient to the user. To obtain an optimal partition of the code point space for this trie resulting in the fewest number of ranges, see [CodePointTrie::iter_ranges()].

Examples

use icu::collections::codepointtrie::planes;

let trie = planes::get_planes_trie();

const CODE_POINT_MAX: u32 = 0x10ffff;
let start = 0x1_0000;
let exp_end = 0x1_ffff;

let start_val = trie.get32(start);
assert_eq!(trie.get32(exp_end), start_val);
assert_ne!(trie.get32(exp_end + 1), start_val);

use icu::collections::codepointtrie::CodePointMapRange;

let cpm_range: CodePointMapRange<u8> = trie.get_range(start).unwrap();

assert_eq!(cpm_range.range.start(), &start);
assert_eq!(cpm_range.range.end(), &exp_end);
assert_eq!(cpm_range.value, start_val);

// `start` can be any code point, whether or not it lies on the boundary
// of a maximally large range that still contains `start`

let submaximal_1_start = start + 0x1234;
let submaximal_1 = trie.get_range(submaximal_1_start).unwrap();
assert_eq!(submaximal_1.range.start(), &0x1_1234);
assert_eq!(submaximal_1.range.end(), &0x1_ffff);
assert_eq!(submaximal_1.value, start_val);

let submaximal_2_start = start + 0xffff;
let submaximal_2 = trie.get_range(submaximal_2_start).unwrap();
assert_eq!(submaximal_2.range.start(), &0x1_ffff);
assert_eq!(submaximal_2.range.end(), &0x1_ffff);
assert_eq!(submaximal_2.value, start_val);
fn iter_ranges(self: &Self) -> CodePointMapRangeIterator<'_, T>

Yields an Iterator returning ranges of consecutive code points that share the same value in the CodePointTrie, as given by [CodePointTrie::get_range()].

Examples

use core::ops::RangeInclusive;
use icu::collections::codepointtrie::planes;
use icu::collections::codepointtrie::CodePointMapRange;

let planes_trie = planes::get_planes_trie();

let mut ranges = planes_trie.iter_ranges();

for plane in 0..=16 {
    let exp_start = plane * 0x1_0000;
    let exp_end = exp_start + 0xffff;
    assert_eq!(
        ranges.next(),
        Some(CodePointMapRange {
            range: exp_start..=exp_end,
            value: plane as u8
        })
    );
}

// Hitting the end of the iterator returns `None`, as will subsequent
// calls to .next().
assert_eq!(ranges.next(), None);
assert_eq!(ranges.next(), None);
fn iter_ranges_for_value(self: &Self, value: T) -> impl Iterator<Item = RangeInclusive<u32>> + '_

Yields an Iterator returning the ranges of the code points whose values match value in the CodePointTrie.

Examples

use icu::collections::codepointtrie::planes;

let trie = planes::get_planes_trie();

let plane_val = 2;
let mut sip_range_iter = trie.iter_ranges_for_value(plane_val as u8);

let start = plane_val * 0x1_0000;
let end = start + 0xffff;

let sip_range = sip_range_iter.next()
    .expect("Plane 2 (SIP) should exist in planes data");
assert_eq!(start..=end, sip_range);

assert!(sip_range_iter.next().is_none());
fn iter_ranges_mapped<'a, U: Eq + 'a, impl FnMut(T) -> U + Copy + 'a: FnMut(T) -> U + Copy + 'a>(self: &'a Self, map: impl FnMut(T) -> U + Copy + 'a) -> impl Iterator<Item = CodePointMapRange<U>> + 'a

Yields an Iterator returning the ranges of the code points after passing the value through a mapping function.

This is preferable to calling .get_ranges().map() since it will coalesce adjacent ranges into one.

Examples

use icu::collections::codepointtrie::planes;

let trie = planes::get_planes_trie();

let plane_val = 2;
let mut sip_range_iter = trie.iter_ranges_mapped(|value| value != plane_val as u8).filter(|range| range.value);

let end = plane_val * 0x1_0000 - 1;

let sip_range = sip_range_iter.next()
    .expect("Complemented planes data should have at least one entry");
assert_eq!(0..=end, sip_range.range);
fn error_value(self: &Self) -> T

Returns the value used as an error value for this trie

impl<T: TrieValue + Into<u32>> CodePointTrie<'_, T>

fn get32_u32(self: &Self, code_point: u32) -> u32

Returns the value that is associated with code_point for this CodePointTrie as a u32.

Examples

use icu::collections::codepointtrie::planes;
let trie = planes::get_planes_trie();

let cp = '𑖎' as u32;
assert_eq!(cp, 0x1158E);

let plane_num: u8 = trie.get32(cp);
assert_eq!(trie.get32_u32(cp), plane_num as u32);

impl<'a, T> Yokeable for CodePointTrie<'static, T>

fn transform(self: &'a Self) -> &'a <Self as >::Output
fn transform_owned(self: Self) -> <Self as >::Output
unsafe fn make(this: <Self as >::Output) -> Self
fn transform_mut<F>(self: &'a mut Self, f: F)
where
    F: 'static + for<'b> FnOnce(&'b mut <Self as >::Output)

impl<'trie, T> Freeze for CodePointTrie<'trie, T>

impl<'trie, T> RefUnwindSafe for CodePointTrie<'trie, T>

impl<'trie, T> Send for CodePointTrie<'trie, T>

impl<'trie, T> Sync for CodePointTrie<'trie, T>

impl<'trie, T> Unpin for CodePointTrie<'trie, T>

impl<'trie, T> UnsafeUnpin for CodePointTrie<'trie, T>

impl<'trie, T> UnwindSafe for CodePointTrie<'trie, T>

impl<'trie, T: $crate::cmp::Eq + TrieValue> Eq for CodePointTrie<'trie, T>

impl<'trie, T: $crate::cmp::PartialEq + TrieValue> PartialEq for CodePointTrie<'trie, T>

fn eq(self: &Self, other: &CodePointTrie<'trie, T>) -> bool

impl<'trie, T: $crate::fmt::Debug + TrieValue> Debug for CodePointTrie<'trie, T>

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

impl<'trie, T: TrieValue> StructuralPartialEq for CodePointTrie<'trie, T>

impl<'zf, 'zf_inner, T: TrieValue> ZeroFrom for CodePointTrie<'zf, T>

fn zero_from(this: &'zf CodePointTrie<'zf_inner, T>) -> Self

impl<T> Any for CodePointTrie<'trie, T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for CodePointTrie<'trie, T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for CodePointTrie<'trie, T>

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

impl<T> CloneToUninit for CodePointTrie<'trie, T>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> ErasedDestructor for CodePointTrie<'trie, T>

impl<T> From for CodePointTrie<'trie, T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for CodePointTrie<'trie, T>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for CodePointTrie<'trie, T>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for CodePointTrie<'trie, T>

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

impl<T, U> TryInto for CodePointTrie<'trie, T>

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

impl<T: TrieValue> Clone for CodePointTrie<'_, T>

fn clone(self: &Self) -> Self