factorio-ir 0.5.0

Intermediate representation for factorio-rs Rust-to-Lua Factorio mod transpilation
Documentation
//! Rust source origin for sourcemaps and debug adapters.

use std::sync::Arc;

/// Location in a Rust source file (1-based line/column).
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Origin {
    pub file: Arc<str>,
    pub line: u32,
    pub column: u32,
}

impl Origin {
    #[must_use]
    pub fn new(file: impl Into<Arc<str>>, line: u32, column: u32) -> Self {
        Self {
            file: file.into(),
            line,
            column: column.max(1),
        }
    }

    /// Format as `path:line:column` (or `path:line` when column is 1).
    #[must_use]
    pub fn display(&self) -> String {
        if self.column <= 1 {
            format!("{}:{}", self.file, self.line)
        } else {
            format!("{}:{}:{}", self.file, self.line, self.column)
        }
    }
}