bve 0.0.1

Remaking OpenBVE using a modern architecture, using Unity and Rust.
use num_traits::ToPrimitive;

/// File location for errors/ast nodes
///
/// Does not contain file information because they are already associated with an attempt to parse a file.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Span {
    /// Line of the location
    ///
    /// May be empty if there is no reasonable way to create a span for a construct.
    /// Empty spans generally should not be exposed to the user.
    pub line: Option<u64>,
}

impl Span {
    #[must_use]
    pub const fn new() -> Self {
        Self { line: None }
    }

    #[must_use]
    pub const fn none() -> Self {
        Self { line: None }
    }

    #[must_use]
    pub fn from_line(line: impl ToPrimitive + Copy) -> Self {
        Self { line: line.to_u64() }
    }
}

impl<'a> From<Option<&'a csv::Position>> for Span {
    #[must_use]
    fn from(p: Option<&'a csv::Position>) -> Self {
        Self {
            line: p.map(csv::Position::line),
        }
    }
}