pub struct LineCol {
pub line: u32,
pub col: u32,
}Expand description
A resolved human coordinate: a 1-based line and a 1-based column.
The column counts Unicode scalar values (Rust chars), not bytes, not
UTF-16 code units, and not grapheme clusters. A column therefore never lands
inside a multi-byte UTF-8 sequence: the third char of a line is always
column 3, whether the preceding characters were one byte each or four.
Both fields are 1-based because that is what editors, compilers, and language servers display — line 1, column 1 is the first character of the source.
LineCol is produced by LineIndex::line_col
and consumed by LineIndex::offset; the two are
inverses for every valid byte position.
§Examples
use span_lang::LineCol;
let lc = LineCol::new(2, 5);
assert_eq!(lc.line, 2);
assert_eq!(lc.col, 5);
assert_eq!(lc.to_string(), "2:5");Fields§
§line: u32The 1-based line number.
col: u32The 1-based column, counted in Unicode scalar values (chars).
Implementations§
Source§impl LineCol
impl LineCol
Sourcepub const fn new(line: u32, col: u32) -> Self
pub const fn new(line: u32, col: u32) -> Self
Constructs a coordinate from a 1-based line and column.
This is a plain constructor; it does not validate that the coordinate
exists in any particular source. Resolving a coordinate back to a byte
offset is LineIndex::offset, which reports a
position outside the source as None.
§Examples
use span_lang::LineCol;
const ORIGIN: LineCol = LineCol::new(1, 1);
assert_eq!((ORIGIN.line, ORIGIN.col), (1, 1));