use thiserror::Error;
use std::result::Result as StdResult;
#[derive(Debug, Error, PartialEq, Eq)]
pub enum Error {
#[error("Not a pair")]
NotAPair,
#[error("Key must be a string")]
KeyMustBeAString,
#[error("Cannot serialize {0} as object")]
CannotSerializeAsObject(String),
#[error("Custom({0})")]
Custom(String)
}
impl serde::ser::Error for Error {
fn custom<T>(msg:T) -> Self where T:std::fmt::Display {
Error::Custom(msg.to_string())
}
}
impl From<serde_json::Error> for Error {
fn from(error: serde_json::Error) -> Self {
Error::Custom(format!("serde_json::Error({error})"))
}
}
pub type Result<T> = StdResult<T, Error>;