prism_parser/core/
span.rs1use crate::core::pos::Pos;
2use serde::{Deserialize, Serialize};
3use std::ops::Index;
4
5#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
6pub struct Span {
7 pub start: Pos,
8 pub end: Pos,
9}
10
11impl Span {
12 pub fn new(start: Pos, end: Pos) -> Self {
13 Span { start, end }
14 }
15
16 pub const fn invalid() -> Self {
17 Span {
18 start: Pos::invalid(),
19 end: Pos::invalid(),
20 }
21 }
22}
23
24impl Index<Span> for str {
25 type Output = str;
26
27 fn index(&self, index: Span) -> &Self::Output {
28 &self[index.start.into()..index.end.into()]
29 }
30}