pub struct CodePointTrie<'trie, T: TrieValue> { /* private fields */ }
Expand description

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

For more information:

Implementations

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

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

Examples
use icu_codepointtrie::planes;
let trie = planes::get_planes_trie();

assert_eq!(0, trie.get(0x41));  // 'A' as u32
assert_eq!(0, trie.get(0x13E0));  // 'Ꮰ' as u32
assert_eq!(1, trie.get(0x10044));  // '𐁄' as u32

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

Examples
use icu_codepointtrie::planes;
let trie = planes::get_planes_trie();

assert_eq!(Some(&0), trie.get_ule(0x41));  // 'A' as u32
assert_eq!(Some(&0), trie.get_ule(0x13E0));  // 'Ꮰ' as u32
assert_eq!(Some(&1), trie.get_ule(0x10044));  // '𐁄' as u32

Converts the CodePointTrie into one that returns another type of the same size.

Borrowed data remains borrowed, and owned data remains owned.

Panics

Panics if T and P are different sizes.

More specifically, panics if ZeroVec::try_into_converted() panics when converting ZeroVec<T> into ZeroVec<P>, which happens if T::ULE and P::ULE differ in size.

Examples
use icu_codepointtrie::CodePointTrie;

let cpt1: CodePointTrie<char> = unimplemented!();
let cpt2: CodePointTrie<u32> = cpt1.try_into_converted()
    .expect("infallible");

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_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.get(start);
assert_eq!(trie.get(exp_end), start_val);
assert_ne!(trie.get(exp_end + 1), start_val);

use core::ops::RangeInclusive;
use icu_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);

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_codepointtrie::CodePointMapRange;
use icu_codepointtrie::planes;

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: RangeInclusive::new(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);

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

Examples
use icu_codepointtrie::planes;

let trie = planes::get_planes_trie();

let plane_val = 2;
let mut sip_range_iter = trie.get_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());

Returns a UnicodeSet for the code points that have the given TrieValue in the trie.

Examples
use icu_codepointtrie::planes;

let trie = planes::get_planes_trie();

let plane_val = 2;
let sip = trie.get_set_for_value(plane_val as u8);

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

assert!(!sip.contains_u32(start - 1));
assert!(sip.contains_u32(start));
assert!(sip.contains_u32(end));
assert!(!sip.contains_u32(end + 1));

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

Examples
use icu_codepointtrie::planes;
let trie = planes::get_planes_trie();

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

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

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

Deserialize this value from the given Serde deserializer. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

This type MUST be Self with the 'static replaced with 'a, i.e. Self<'a>

This method must cast self between &'a Self<'static> and &'a Self<'a>. Read more

This method must cast self between Self<'static> and Self<'a>. Read more

This method can be used to cast away Self<'a>’s lifetime. Read more

This method must cast self between &'a mut Self<'static> and &'a mut Self<'a>, and pass it to f. Read more

Clone the other C into a struct that may retain references into C.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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.