pub trait GetCharacterSet {
// Required method
fn get_set(&self) -> &[char];
// Provided methods
fn size(&self) -> usize { ... }
fn get_character(&self, index: u32) -> Option<&char> { ... }
fn character_to_bits(&self, chr: &char) -> u32 { ... }
}Expand description
This trait is used for reading unicode set data.
New sets should implement get_set which provides the array with
unicode characters used by the method.
Required Methods§
Provided Methods§
fn size(&self) -> usize
Sourcefn get_character(&self, index: u32) -> Option<&char>
fn get_character(&self, index: u32) -> Option<&char>
Maps index (in other words, the value) to the character in the set.
§Arguments
index- the value which will be mapped (i.e. index of the character in the set)
§Examples
§Gets character which is in the set
use ptero::method::trailing_unicode::character_sets::{CharacterSetType, GetCharacterSet};
let set = CharacterSetType::FullUnicodeSet;
assert_eq!(set.get_character(1), Some(&'\u{0020}'));
assert_eq!(set.get_character(2), Some(&'\u{2000}'));
assert_eq!(set.get_character(31), Some(&'\u{FEFF}'));§Returns None if value cannot be mapped
use ptero::method::trailing_unicode::character_sets::{CharacterSetType, GetCharacterSet};
let set = CharacterSetType::FullUnicodeSet;
assert_eq!(set.get_character(0), None);§Panics
The method panics if the provided value is larger than the set size.
§Panics if index exceeds the size of the set
ⓘ
use ptero::method::trailing_unicode::character_sets::{CharacterSetType, GetCharacterSet};
let set = CharacterSetType::FullUnicodeSet;
set.get_character(100);Sourcefn character_to_bits(&self, chr: &char) -> u32
fn character_to_bits(&self, chr: &char) -> u32
Returns the number represented by the character. The number is the bit representation of the character - or in other words the index. If the character is not recognized it returns 0 by default.
§Arguments
chr- character which will be converted
§Examples
§Converts recognized character
use ptero::method::trailing_unicode::character_sets::{CharacterSetType, GetCharacterSet};
let set = CharacterSetType::FullUnicodeSet;
let value = set.character_to_bits(&'\u{200A}');
assert_eq!(value, 11);§Converts unrecognized character to 0
use ptero::method::trailing_unicode::character_sets::{CharacterSetType, GetCharacterSet};
let set = CharacterSetType::FullUnicodeSet;
let value = set.character_to_bits(&'A');
assert_eq!(value, 0);