1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::ops::Range;

use derive_more::{Constructor, Display};

use crate::structure::Located;

#[derive(Constructor, Clone, Copy, Debug, Ord, PartialOrd, Eq, PartialEq, Default, Display)]
#[display(fmt = "...{}:{}", offset, length)]
pub struct CodePoint {
    pub length: usize,
    pub offset: usize,
}

impl CodePoint {
    #[must_use]
    pub const fn single_point(offset: usize) -> Self {
        Self { length: 1, offset }
    }

    pub const fn as_range(&self) -> Range<usize> {
        self.offset..self.offset + self.length
    }
}

impl Located for CodePoint {
    fn location(&self) -> CodePoint {
        *self
    }
}