use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ParseErrorKind {
Json,
RootNotObject,
TooLarge {
limit: usize,
actual: usize,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseError {
kind: ParseErrorKind,
message: String,
}
impl ParseError {
pub(crate) fn new(kind: ParseErrorKind, message: impl Into<String>) -> Self {
Self {
kind,
message: message.into(),
}
}
#[must_use]
pub fn kind(&self) -> &ParseErrorKind {
&self.kind
}
#[must_use]
pub fn message(&self) -> &str {
&self.message
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.message)
}
}
impl std::error::Error for ParseError {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UrlError {
message: String,
}
impl UrlError {
pub(crate) fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
#[must_use]
pub fn message(&self) -> &str {
&self.message
}
}
impl fmt::Display for UrlError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.message)
}
}
impl std::error::Error for UrlError {}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
Parse(ParseError),
Url(UrlError),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Parse(error) => write!(f, "invalid apple-app-site-association: {error}"),
Self::Url(error) => write!(f, "invalid URL: {error}"),
}
}
}
impl std::error::Error for Error {}
impl From<ParseError> for Error {
fn from(error: ParseError) -> Self {
Self::Parse(error)
}
}
impl From<UrlError> for Error {
fn from(error: UrlError) -> Self {
Self::Url(error)
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;