cl-structures: Make Span and Loc functions const (now you can make a const Span!)
This commit is contained in:
parent
b74c4cd5bf
commit
45d75bb552
@ -8,24 +8,33 @@ pub struct Span {
|
|||||||
pub head: Loc,
|
pub head: Loc,
|
||||||
pub tail: Loc,
|
pub tail: Loc,
|
||||||
}
|
}
|
||||||
pub fn Span(head: Loc, tail: Loc) -> Span {
|
pub const fn Span(head: Loc, tail: Loc) -> Span {
|
||||||
Span { head, tail }
|
Span { head, tail }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Span {
|
||||||
|
pub const fn dummy() -> Self {
|
||||||
|
Span { head: Loc::dummy(), tail: Loc::dummy() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Stores a read-only (line, column) location in a token stream
|
/// Stores a read-only (line, column) location in a token stream
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct Loc {
|
pub struct Loc {
|
||||||
line: u32,
|
line: u32,
|
||||||
col: u32,
|
col: u32,
|
||||||
}
|
}
|
||||||
pub fn Loc(line: u32, col: u32) -> Loc {
|
pub const fn Loc(line: u32, col: u32) -> Loc {
|
||||||
Loc { line, col }
|
Loc { line, col }
|
||||||
}
|
}
|
||||||
impl Loc {
|
impl Loc {
|
||||||
pub fn line(self) -> u32 {
|
pub const fn dummy() -> Self {
|
||||||
|
Loc { line: 0, col: 0 }
|
||||||
|
}
|
||||||
|
pub const fn line(self) -> u32 {
|
||||||
self.line
|
self.line
|
||||||
}
|
}
|
||||||
pub fn col(self) -> u32 {
|
pub const fn col(self) -> u32 {
|
||||||
self.col
|
self.col
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user