use std::{borrow::Cow, io};
use thiserror::Error;
pub type Result<T> = std::result::Result<T, OciSpecError>;
#[derive(Error, Debug)]
pub enum OciSpecError {
#[error("{0}")]
Other(String),
#[error("io operation failed")]
Io(#[from] io::Error),
#[error("serde failed")]
SerDe(#[from] serde_json::Error),
#[error("uninitialized field")]
Builder(#[from] derive_builder::UninitializedFieldError),
}
pub(crate) fn oci_error<'a, M>(message: M) -> OciSpecError
where
M: Into<Cow<'a, str>>,
{
let message = message.into();
match message {
Cow::Borrowed(s) => OciSpecError::Other(s.to_owned()),
Cow::Owned(s) => OciSpecError::Other(s),
}
}