This commit is contained in:
Qyriad 2026-01-28 19:30:59 +01:00
parent 34a9c3f864
commit 551e5a7851
4 changed files with 163 additions and 33 deletions

View file

@ -9,24 +9,35 @@ pub struct Line(pub u64);
/// Constructors.
impl Line {
pub fn from_index(index: u64) -> Self {
pub const fn from_index(index: u64) -> Self {
Self(index)
}
pub fn from_linenr(linenr: NonZeroU64) -> Self {
pub const fn from_linenr(linenr: NonZeroU64) -> Self {
Self(linenr.get() - 1)
}
pub const fn next(self) -> Self {
Self::from_index(self.index() + 1)
}
/// Panics if self is line index 0.
pub const fn prev(self) -> Self {
Self::from_index(self.index() - 1)
}
}
/// Getters.
impl Line {
/// 0-indexed
pub fn index(self) -> u64 {
pub const fn index(self) -> u64 {
self.0
}
/// 1-indexed
pub fn linenr(self) -> u64 {
pub const fn linenr(self) -> u64 {
self.0 + 1
}
}
pub struct Lines(Vec<Line>);