mca_parser/error.rs
1//! Module which contains information about potential errors that may occur while using this crate
2
3use std::{fmt::Debug, io};
4
5/// The general error type which wraps other errors
6#[derive(Debug)]
7pub enum Error {
8 /// An error that may occur when parsing NBT data
9 NbtError(fastnbt::error::Error),
10 /// An error that may occur when decompressing data
11 DecompressError(miniz_oxide::inflate::DecompressError),
12 /// An error that may occur when interaction with an [`io`] item
13 IoError(io::Error),
14 /// An error that may occur when the header of a region file is missing
15 MissingHeader,
16 /// An error that may occur when more data is expected by a parser than is provided
17 UnexpectedEof,
18 /// A custom error type that is not used within this crate, but may be needed for implementors
19 /// of the traits within this crate.
20 Custom(String),
21}
22
23macro_rules! error_wrap {
24 ($type: ty => $val: ident) => {
25 impl From<$type> for Error {
26 fn from(value: $type) -> Self {
27 Error::$val(value)
28 }
29 }
30 };
31}
32
33error_wrap!(fastnbt::error::Error => NbtError);
34error_wrap!(miniz_oxide::inflate::DecompressError => DecompressError);
35error_wrap!(std::io::Error => IoError);
36
37/// A type alias used throughout the create to reduce repetition of the [`Error`] enum
38pub type Result<T> = std::result::Result<T, Error>;