Thanks to visit codestin.com
Credit goes to docs.rs

unicode_blocks/
unicode_block.rs

1use core::{
2    cmp::Ordering,
3    hash::{Hash, Hasher},
4};
5
6#[derive(Debug, Copy, Clone, Eq)]
7pub struct UnicodeBlock {
8    pub(crate) name:  &'static str,
9    pub(crate) start: u32,
10    pub(crate) end:   u32,
11}
12
13impl UnicodeBlock {
14    #[inline]
15    pub const fn name(&self) -> &'static str {
16        self.name
17    }
18
19    #[inline]
20    pub const fn start(&self) -> u32 {
21        self.start
22    }
23
24    #[inline]
25    pub const fn end(&self) -> u32 {
26        self.end
27    }
28}
29
30impl UnicodeBlock {
31    /// Given a character, determine whether this unicode block contains it.
32    #[inline]
33    pub fn contains(&self, c: char) -> bool {
34        let u = c as u32;
35
36        u >= self.start && u <= self.end
37    }
38}
39
40impl PartialEq for UnicodeBlock {
41    #[inline]
42    fn eq(&self, other: &UnicodeBlock) -> bool {
43        self.start.eq(&other.start)
44    }
45}
46
47impl PartialOrd for UnicodeBlock {
48    #[inline]
49    fn partial_cmp(&self, other: &UnicodeBlock) -> Option<Ordering> {
50        Some(self.cmp(other))
51    }
52}
53
54impl Ord for UnicodeBlock {
55    #[inline]
56    fn cmp(&self, other: &UnicodeBlock) -> Ordering {
57        self.start.cmp(&other.start)
58    }
59}
60
61impl Hash for UnicodeBlock {
62    #[inline]
63    fn hash<H: Hasher>(&self, state: &mut H) {
64        self.start.hash(state)
65    }
66}