Struct icu::collections::codepointtrie::CodePointTrie
source · [−]pub struct CodePointTrie<'trie, T> where
T: TrieValue, { /* private fields */ }
Expand description
This struct represents a de-serialized CodePointTrie that was exported from ICU binary data.
For more information:
Implementations
sourceimpl<'trie, T> CodePointTrie<'trie, T> where
T: TrieValue,
impl<'trie, T> CodePointTrie<'trie, T> where
T: TrieValue,
sourcepub fn try_new(
header: CodePointTrieHeader,
index: ZeroVec<'trie, u16>,
data: ZeroVec<'trie, T>
) -> Result<CodePointTrie<'trie, T>, Error>
pub 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
.
sourcepub fn get32(&self, code_point: u32) -> T
pub fn get32(&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
sourcepub fn get(&self, c: char) -> T
pub fn get(&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
sourcepub fn get32_ule(&self, code_point: u32) -> Option<&<T as AsULE>::ULE>
pub fn get32_ule(&self, code_point: u32) -> Option<&<T as AsULE>::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
sourcepub fn try_into_converted<P>(
self
) -> Result<CodePointTrie<'trie, P>, ZeroVecError> where
P: TrieValue,
pub fn try_into_converted<P>(
self
) -> Result<CodePointTrie<'trie, P>, ZeroVecError> where
P: TrieValue,
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_collections::codepointtrie::CodePointTrie;
let cpt1: CodePointTrie<char> = unimplemented!();
let cpt2: CodePointTrie<u32> =
cpt1.try_into_converted().expect("infallible");
sourcepub fn get_range(&self, start: u32) -> Option<CodePointMapRange<T>>
pub fn get_range(&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 core::ops::RangeInclusive;
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);
sourcepub fn iter_ranges(&self) -> CodePointMapRangeIterator<'_, T>ⓘNotable traits for CodePointMapRangeIterator<'a, T>impl<'a, T> Iterator for CodePointMapRangeIterator<'a, T> where
T: TrieValue, type Item = CodePointMapRange<T>;
pub fn iter_ranges(&self) -> CodePointMapRangeIterator<'_, T>ⓘNotable traits for CodePointMapRangeIterator<'a, T>impl<'a, T> Iterator for CodePointMapRangeIterator<'a, T> where
T: TrieValue, type Item = CodePointMapRange<T>;
T: TrieValue, type Item = CodePointMapRange<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: 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);
sourcepub fn get_ranges_for_value(
&self,
value: T
) -> impl Iterator<Item = RangeInclusive<u32>>
pub fn get_ranges_for_value(
&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.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());
sourcepub fn get_set_for_value(&self, value: T) -> CodePointInversionList<'static>
pub fn get_set_for_value(&self, value: T) -> CodePointInversionList<'static>
Returns a CodePointInversionList
for the code points that have the given
TrieValue
in the trie.
Examples
use icu_collections::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.contains32(start - 1));
assert!(sip.contains32(start));
assert!(sip.contains32(end));
assert!(!sip.contains32(end + 1));
sourcepub fn error_value(&self) -> T
pub fn error_value(&self) -> T
Returns the value used as an error value for this trie
sourceimpl<'trie, T> CodePointTrie<'trie, T> where
T: TrieValue + Into<u32>,
impl<'trie, T> CodePointTrie<'trie, T> where
T: TrieValue + Into<u32>,
sourcepub fn get32_u32(&self, code_point: u32) -> u32
pub fn get32_u32(&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);
Trait Implementations
sourceimpl<'trie, T> Bake for CodePointTrie<'trie, T> where
T: TrieValue + Bake,
impl<'trie, T> Bake for CodePointTrie<'trie, T> where
T: TrieValue + Bake,
sourcefn bake(&self, env: &CrateEnv) -> TokenStream
fn bake(&self, env: &CrateEnv) -> TokenStream
Returns a TokenStream
that would evaluate to self
. Read more
sourceimpl<'trie, T> Clone for CodePointTrie<'trie, T> where
T: TrieValue,
<T as AsULE>::ULE: Clone,
impl<'trie, T> Clone for CodePointTrie<'trie, T> where
T: TrieValue,
<T as AsULE>::ULE: Clone,
sourcefn clone(&self) -> CodePointTrie<'trie, T>
fn clone(&self) -> CodePointTrie<'trie, T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'trie, T> Debug for CodePointTrie<'trie, T> where
T: Debug + TrieValue,
impl<'trie, T> Debug for CodePointTrie<'trie, T> where
T: Debug + TrieValue,
sourceimpl<'de, 'trie, T> Deserialize<'de> for CodePointTrie<'trie, T> where
'de: 'trie,
T: TrieValue + Deserialize<'de>,
impl<'de, 'trie, T> Deserialize<'de> for CodePointTrie<'trie, T> where
'de: 'trie,
T: TrieValue + Deserialize<'de>,
sourcefn deserialize<D>(
deserializer: D
) -> Result<CodePointTrie<'trie, T>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<CodePointTrie<'trie, T>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<'trie, T> PartialEq<CodePointTrie<'trie, T>> for CodePointTrie<'trie, T> where
T: PartialEq<T> + TrieValue,
impl<'trie, T> PartialEq<CodePointTrie<'trie, T>> for CodePointTrie<'trie, T> where
T: PartialEq<T> + TrieValue,
sourcefn eq(&self, other: &CodePointTrie<'trie, T>) -> bool
fn eq(&self, other: &CodePointTrie<'trie, T>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &CodePointTrie<'trie, T>) -> bool
fn ne(&self, other: &CodePointTrie<'trie, T>) -> bool
This method tests for !=
.
sourceimpl<'trie, T> Serialize for CodePointTrie<'trie, T> where
T: TrieValue + Serialize,
impl<'trie, T> Serialize for CodePointTrie<'trie, T> where
T: TrieValue + Serialize,
sourcefn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
sourceimpl<'_, T> TryFrom<&'_ CodePointTrieToml> for CodePointTrie<'static, T> where
T: TrieValue,
impl<'_, T> TryFrom<&'_ CodePointTrieToml> for CodePointTrie<'static, T> where
T: TrieValue,
sourcefn try_from(
cpt_data: &CodePointTrieToml
) -> Result<CodePointTrie<'static, T>, <CodePointTrie<'static, T> as TryFrom<&'_ CodePointTrieToml>>::Error>
fn try_from(
cpt_data: &CodePointTrieToml
) -> Result<CodePointTrie<'static, T>, <CodePointTrie<'static, T> as TryFrom<&'_ CodePointTrieToml>>::Error>
Performs the conversion.
sourceimpl<'a, T> Yokeable<'a> for CodePointTrie<'static, T> where
T: TrieValue + 'static,
impl<'a, T> Yokeable<'a> for CodePointTrie<'static, T> where
T: TrieValue + 'static,
type Output = CodePointTrie<'a, T>
type Output = CodePointTrie<'a, T>
This type MUST be Self
with the 'static
replaced with 'a
, i.e. Self<'a>
sourcefn transform(
&'a self
) -> &'a <CodePointTrie<'static, T> as Yokeable<'a>>::Output
fn transform(
&'a self
) -> &'a <CodePointTrie<'static, T> as Yokeable<'a>>::Output
This method must cast self
between &'a Self<'static>
and &'a Self<'a>
. Read more
sourcefn transform_owned(self) -> <CodePointTrie<'static, T> as Yokeable<'a>>::Output
fn transform_owned(self) -> <CodePointTrie<'static, T> as Yokeable<'a>>::Output
This method must cast self
between Self<'static>
and Self<'a>
. Read more
sourceunsafe fn make(
this: <CodePointTrie<'static, T> as Yokeable<'a>>::Output
) -> CodePointTrie<'static, T>
unsafe fn make(
this: <CodePointTrie<'static, T> as Yokeable<'a>>::Output
) -> CodePointTrie<'static, T>
This method can be used to cast away Self<'a>
’s lifetime. Read more
sourcefn transform_mut<F>(&'a mut self, f: F) where
F: 'static + for<'b> FnOnce(&'b mut <CodePointTrie<'static, T> as Yokeable<'a>>::Output),
fn transform_mut<F>(&'a mut self, f: F) where
F: 'static + for<'b> FnOnce(&'b mut <CodePointTrie<'static, T> as Yokeable<'a>>::Output),
This method must cast self
between &'a mut Self<'static>
and &'a mut Self<'a>
,
and pass it to f
. Read more
sourceimpl<'zf, 'zf_inner, T> ZeroFrom<'zf, CodePointTrie<'zf_inner, T>> for CodePointTrie<'zf, T> where
T: TrieValue,
ZeroVec<'zf, T>: ZeroFrom<'zf, ZeroVec<'zf_inner, T>>,
impl<'zf, 'zf_inner, T> ZeroFrom<'zf, CodePointTrie<'zf_inner, T>> for CodePointTrie<'zf, T> where
T: TrieValue,
ZeroVec<'zf, T>: ZeroFrom<'zf, ZeroVec<'zf_inner, T>>,
sourcefn zero_from(this: &'zf CodePointTrie<'zf_inner, T>) -> CodePointTrie<'zf, T>
fn zero_from(this: &'zf CodePointTrie<'zf_inner, T>) -> CodePointTrie<'zf, T>
Clone the other C
into a struct that may retain references into C
.
impl<'trie, T> Eq for CodePointTrie<'trie, T> where
T: Eq + TrieValue,
impl<'a, T> IsCovariant<'a> for CodePointTrie<'a, T> where
T: TrieValue + 'static,
impl<'trie, T> StructuralEq for CodePointTrie<'trie, T> where
T: TrieValue,
impl<'trie, T> StructuralPartialEq for CodePointTrie<'trie, T> where
T: TrieValue,
Auto Trait Implementations
impl<'trie, T> RefUnwindSafe for CodePointTrie<'trie, T> where
T: RefUnwindSafe,
<T as AsULE>::ULE: RefUnwindSafe,
impl<'trie, T> Send for CodePointTrie<'trie, T> where
T: Send,
<T as AsULE>::ULE: Send + Sync,
impl<'trie, T> Sync for CodePointTrie<'trie, T> where
T: Sync,
<T as AsULE>::ULE: Sync,
impl<'trie, T> Unpin for CodePointTrie<'trie, T> where
T: Unpin,
<T as AsULE>::ULE: Unpin,
impl<'trie, T> UnwindSafe for CodePointTrie<'trie, T> where
T: UnwindSafe,
<T as AsULE>::ULE: UnwindSafe + RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Serialize for T where
T: Serialize + ?Sized,
impl<T> Serialize for T where
T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more