PoC
This commit is contained in:
parent
34a9c3f864
commit
551e5a7851
4 changed files with 163 additions and 33 deletions
19
src/line.rs
19
src/line.rs
|
|
@ -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>);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue