Skip to main content

vvv_core/text/
position.rs

1use serde::{Deserialize, Serialize};
2
3/// Zero-based line and character column. Columns count `char`s, not bytes,
4/// so they are safe to show to humans and editors.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
6pub struct Position {
7    pub line: u32,
8    pub column: u32,
9}
10
11impl Position {
12    pub fn new(line: u32, column: u32) -> Self {
13        Self { line, column }
14    }
15
16    /// One-based rendering for terminals (`12:4`).
17    pub fn display(&self) -> String {
18        format!("{}:{}", self.line + 1, self.column + 1)
19    }
20}