kodept_core/
code_point.rs1use std::ops::Range;
2
3use derive_more::{Constructor, Display};
4
5use crate::structure::Located;
6
7#[derive(Constructor, Clone, Copy, Debug, Ord, PartialOrd, Eq, PartialEq, Default, Display)]
8#[display("...{}:{}", offset, length)]
9pub struct CodePoint {
10 pub length: u32,
11 pub offset: u32,
12}
13
14impl CodePoint {
15 #[must_use]
16 pub const fn single_point(offset: u32) -> Self {
17 Self {
18 length: 1,
19 offset,
20 }
21 }
22
23 pub const fn as_range(&self) -> Range<usize> {
24 let offset = self.offset as usize;
25 let length = self.length as usize;
26 offset..offset + length
27 }
28}
29
30impl Located for CodePoint {
31 fn location(&self) -> CodePoint {
32 *self
33 }
34}