diff options
author | Blaž Hrastnik | 2020-05-20 09:14:51 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-05-20 09:14:51 +0000 |
commit | 240e5f4e3d27415b792776dd126d15302d53e83b (patch) | |
tree | 8579f77ca5d200bafd7df09ab93ceb65e5bdce3b /helix-core |
Initial import.
Diffstat (limited to 'helix-core')
-rw-r--r-- | helix-core/.gitignore | 2 | ||||
-rw-r--r-- | helix-core/Cargo.toml | 11 | ||||
-rw-r--r-- | helix-core/src/lib.rs | 5 | ||||
-rw-r--r-- | helix-core/src/position.rs | 27 | ||||
-rw-r--r-- | helix-core/src/range.rs | 9 |
5 files changed, 54 insertions, 0 deletions
diff --git a/helix-core/.gitignore b/helix-core/.gitignore new file mode 100644 index 00000000..96ef6c0b --- /dev/null +++ b/helix-core/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml new file mode 100644 index 00000000..446e8e42 --- /dev/null +++ b/helix-core/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "helix-core" +version = "0.1.0" +authors = ["Blaž Hrastnik <blaz@mxxn.io>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ropey = "1.1.0" +# slab = "0.4.2" diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs new file mode 100644 index 00000000..71a66030 --- /dev/null +++ b/helix-core/src/lib.rs @@ -0,0 +1,5 @@ +mod position; +mod range; + +use position::Position; +use range::Range; diff --git a/helix-core/src/position.rs b/helix-core/src/position.rs new file mode 100644 index 00000000..8c82b83b --- /dev/null +++ b/helix-core/src/position.rs @@ -0,0 +1,27 @@ +/// Represents a single point in a text buffer. Zero indexed. +#[derive(Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub struct Position { + pub row: usize, + pub col: usize, +} + +impl Position { + pub fn new(row: usize, col: usize) -> Self { + Self { row, col } + } + + pub fn is_zero(self) -> bool { + self.row == 0 && self.col == 0 + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_ordering() { + // (0, 5) is less than (1, 0 w v f) + assert!(Position::new(0, 5) < Position::new(1, 0)); + } +} diff --git a/helix-core/src/range.rs b/helix-core/src/range.rs new file mode 100644 index 00000000..46411664 --- /dev/null +++ b/helix-core/src/range.rs @@ -0,0 +1,9 @@ +use crate::Position; + +#[derive(Clone, Copy, PartialEq, Eq)] +pub struct Range { + pub start: Position, + pub end: Position, +} + +// range traversal iters |