foch 0.0.2

EU4 mod analysis and merge toolkit
Documentation
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::path::PathBuf;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ParseErrorKind {
	Io,
	Format,
	/// A mod's own descriptor has a `replace_path` that names no directory
	/// under the game root. Only `load_descriptor` reports it: a launcher's copy
	/// of a descriptor never interprets `replace_path`.
	InvalidReplacePath,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ParseError {
	pub kind: ParseErrorKind,
	pub path: PathBuf,
	pub message: String,
}

impl ParseError {
	pub fn io(path: PathBuf, source: std::io::Error) -> Self {
		Self {
			kind: ParseErrorKind::Io,
			path,
			message: source.to_string(),
		}
	}

	pub fn format(path: PathBuf, message: impl Into<String>) -> Self {
		Self {
			kind: ParseErrorKind::Format,
			path,
			message: message.into(),
		}
	}
}

impl Display for ParseError {
	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
		write!(f, "{}: {}", self.path.display(), self.message)
	}
}

impl Error for ParseError {}