From 240e5f4e3d27415b792776dd126d15302d53e83b Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Wed, 20 May 2020 18:14:51 +0900 Subject: Initial import. --- helix-core/src/position.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 helix-core/src/position.rs (limited to 'helix-core/src/position.rs') 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)); + } +} -- cgit v1.2.3-70-g09d2