svmap 0.3.0

A library to parse SVMap, used to map memory for emulators.
Documentation
use std::fmt;
use crate::AddressType;

/// An error that occurred during parsing of a SVMap file.
#[derive(Clone, PartialEq)]
#[derive(Debug)]
pub enum Error {
    /// A syntax error containing an error message and the line number on which the error occurred.
    Syntax(String, usize),
    /// An invalid identifier error containing the identifier and the line number on which the error
    /// occurred.
    InvalidIdentifier(String, usize),
    /// An integer was bigger than allowed (specifically [`AddressType::MAX`](AddressType)).
    /// Contains the line number on which the error occurred.
    IntegerTooBig(usize),
    /// The file at the specified filepath was not found.
    /// Contains the filepath.
    FileNotFound(String),
    /// Hints that destructuring should not be exhaustive, making it easier to add future error
    /// variants without breaking existing code.
    #[doc(hidden)]
    __NonExhaustive,
}


impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::Syntax(ref err, ref line) => write!(
                f,
                "{} on line {}.",
                err,
                line
            ),
            Error::IntegerTooBig(ref line) => write!(
                f,
                "Integer exceeds size limit of {} on line {}.",
                AddressType::MAX,
                line
            ),
            Error::InvalidIdentifier(ref identifier, ref line) => write!(
                f,
                "Invalid identifier \"{}\" on line {}.",
                identifier,
                line
            ),
            Error::FileNotFound(path) => write!(
                f,
                "File at \"{}\" was not found.",
                path
            ),
            Error::__NonExhaustive => unreachable!(),
        }
    }
}