use std::fmt::{Debug, Display};
use derive_more::Display;
use mediasan_common::error::{ReportStack, ReportableError};
use crate::error::{Result, ResultExt};
use super::{BoxType, FourCC};
#[allow(missing_docs)]
#[derive(Clone, Debug, thiserror::Error)]
pub enum ParseError {
#[error("Invalid box layout")]
InvalidBoxLayout,
#[error("Invalid input")]
InvalidInput,
#[error("Missing required `{_0}` box")]
MissingRequiredBox(BoxType),
#[error("Truncated box")]
TruncatedBox,
#[error("Unsupported box `{_0}`")]
UnsupportedBox(BoxType),
#[error("Unsupported box layout")]
UnsupportedBoxLayout,
#[error("Unsupported format `{_0}`")]
UnsupportedFormat(FourCC),
}
#[doc(hidden)]
pub trait __ParseResultExt: ResultExt + Sized {
fn while_parsing_box(self, box_type: BoxType) -> Self {
self.attach_printable(WhileParsingBox(box_type))
}
fn while_parsing_field<T>(self, box_type: BoxType, field_name: T) -> Self
where
T: Display + Debug + Send + Sync + 'static,
{
self.attach_printable(WhileParsingField(box_type, field_name))
}
fn while_parsing_child(self, box_type: BoxType, child_box_type: BoxType) -> Self {
self.attach_printable(WhileParsingChild(box_type, child_box_type))
}
fn where_eq<T, U>(self, lhs: T, rhs: U) -> Self
where
T: Display + Debug + Send + Sync + 'static,
U: Display + Debug + Send + Sync + 'static,
{
self.attach_printable(WhereEq(lhs, rhs))
}
}
pub(crate) use self::__ParseResultExt as ParseResultExt;
#[derive(Clone, Copy, Debug, Display)]
#[display(fmt = "multiple `{}` boxes", _0)]
pub(crate) struct MultipleBoxes(pub(crate) BoxType);
#[derive(Clone, Copy, Debug, Display)]
#[display(fmt = "while parsing `{}` box", _0)]
pub(crate) struct WhileParsingBox(pub(crate) BoxType);
#[derive(Clone, Copy, Debug, Display)]
#[display(fmt = "while parsing `{}` box field `{}`", _0, _1)]
pub(crate) struct WhileParsingField<T>(pub(crate) BoxType, pub(crate) T);
#[derive(Clone, Copy, Debug, Display)]
#[display(fmt = "while parsing `{}` box child `{}`", _0, _1)]
pub(crate) struct WhileParsingChild(pub(crate) BoxType, pub(crate) BoxType);
#[derive(Clone, Copy, Debug, Display)]
#[display(fmt = "where `{} = {}`", _0, _1)]
pub(crate) struct WhereEq<T, U>(pub(crate) T, pub(crate) U);
impl ReportableError for ParseError {
type Stack = ReportStack;
}
impl<T> ParseResultExt for Result<T, ParseError> {}