Struct icu::properties::maps::CodePointMapDataBorrowed
source · [−]pub struct CodePointMapDataBorrowed<'a, T> where
T: TrieValue, { /* private fields */ }
Expand description
A borrowed wrapper around code point set data, returned by
CodePointSetData::as_borrowed()
. More efficient to query.
Implementations
sourceimpl<'a, T> CodePointMapDataBorrowed<'a, T> where
T: TrieValue,
impl<'a, T> CodePointMapDataBorrowed<'a, T> where
T: TrieValue,
sourcepub fn get(self, ch: char) -> T
pub fn get(self, ch: char) -> T
Get the value this map has associated with code point ch
Example
use icu::properties::{maps, GeneralCategory};
use icu_collections::codepointtrie::CodePointTrie;
let data =
maps::load_general_category(&icu_testdata::unstable())
.expect("The data should be valid");
let gc = data.as_borrowed();
assert_eq!(gc.get('木'), GeneralCategory::OtherLetter); // U+6728
assert_eq!(gc.get('🎃'), GeneralCategory::OtherSymbol); // U+1F383 JACK-O-LANTERN
sourcepub fn get32(self, ch: u32) -> T
pub fn get32(self, ch: u32) -> T
Get the value this map has associated with code point ch
Example
use icu::properties::{maps, GeneralCategory};
use icu_collections::codepointtrie::CodePointTrie;
let data =
maps::load_general_category(&icu_testdata::unstable())
.expect("The data should be valid");
let gc = data.as_borrowed();
assert_eq!(gc.get32(0x6728), GeneralCategory::OtherLetter); // U+6728 (木)
assert_eq!(gc.get32(0x1F383), GeneralCategory::OtherSymbol); // U+1F383 JACK-O-LANTERN
sourcepub fn get_set_for_value(self, value: T) -> CodePointSetData
pub fn get_set_for_value(self, value: T) -> CodePointSetData
Get a CodePointSetData
for all elements corresponding to a particular value
Example
use icu::properties::{maps, GeneralCategory};
use icu_collections::codepointtrie::CodePointTrie;
let data = maps::load_general_category(&icu_testdata::unstable())
.expect("The data should be valid");
let gc = data.as_borrowed();
let other_letter_set_data =
gc.get_set_for_value(GeneralCategory::OtherLetter);
let other_letter_set = other_letter_set_data.as_borrowed();
assert!(other_letter_set.contains('木')); // U+6728
assert!(!other_letter_set.contains('🎃')); // U+1F383 JACK-O-LANTERN
sourcepub fn iter_ranges(self) -> impl Iterator<Item = CodePointMapRange<T>> + 'a
pub fn iter_ranges(self) -> impl Iterator<Item = CodePointMapRange<T>> + 'a
Yields an Iterator
returning ranges of consecutive code points that
share the same value in the CodePointMapData
.
Examples
use core::ops::RangeInclusive;
use icu::properties::maps::CodePointMapData;
use icu_collections::codepointtrie::planes;
use icu_collections::codepointtrie::CodePointMapRange;
let planes_trie = planes::get_planes_trie();
let cp_map_data = CodePointMapData::from_code_point_trie(planes_trie);
let cp_map = cp_map_data.as_borrowed();
let mut ranges = cp_map.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);
Trait Implementations
sourceimpl<'a, T> Clone for CodePointMapDataBorrowed<'a, T> where
T: Clone + TrieValue,
impl<'a, T> Clone for CodePointMapDataBorrowed<'a, T> where
T: Clone + TrieValue,
sourcefn clone(&self) -> CodePointMapDataBorrowed<'a, T>
fn clone(&self) -> CodePointMapDataBorrowed<'a, 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
impl<'a, T> Copy for CodePointMapDataBorrowed<'a, T> where
T: Copy + TrieValue,
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for CodePointMapDataBorrowed<'a, T> where
T: RefUnwindSafe,
<T as AsULE>::ULE: RefUnwindSafe,
impl<'a, T> Send for CodePointMapDataBorrowed<'a, T> where
T: Sync,
<T as AsULE>::ULE: Sync,
impl<'a, T> Sync for CodePointMapDataBorrowed<'a, T> where
T: Sync,
<T as AsULE>::ULE: Sync,
impl<'a, T> Unpin for CodePointMapDataBorrowed<'a, T>
impl<'a, T> UnwindSafe for CodePointMapDataBorrowed<'a, T> where
T: RefUnwindSafe,
<T as AsULE>::ULE: 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> 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)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more