AkurAI Build
Menu

Public repository / master

AkurAI-Framework / crates/json/src/error.rs

Latest change 3ad787ae157fc60f711c536c1811b3b199b0ac1a - init: AkurAI-Framework foundation (history reset after FS corruption) by Ólafur Búi Ólafsson

//! Parse errors, with the character offset where they occurred.

use std::fmt;

/// A JSON parse failure: a human-readable message plus the 0-based character
/// position in the input where parsing gave up.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Error {
    pub message: String,
    pub position: usize,
}

impl Error {
    pub(crate) fn new(message: impl Into<String>, position: usize) -> Error {
        Error {
            message: message.into(),
            position,
        }
    }
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{} at position {}", self.message, self.position)
    }
}

impl std::error::Error for Error {}