use core::fmt;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct LineCol {
pub line: u32,
pub col: u32,
}
impl LineCol {
#[inline]
#[must_use]
pub const fn new(line: u32, col: u32) -> Self {
Self { line, col }
}
}
impl fmt::Display for LineCol {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", self.line, self.col)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_line_col_orders_by_line_then_column() {
assert!(LineCol::new(1, 9) < LineCol::new(2, 1));
assert!(LineCol::new(2, 1) < LineCol::new(2, 2));
}
#[test]
fn test_line_col_display_uses_colon() {
extern crate alloc;
use alloc::string::ToString;
assert_eq!(LineCol::new(10, 3).to_string(), "10:3");
}
}