pub mod content;
pub mod index;
pub mod lock;
pub mod ops;
pub mod project;
pub mod resolve;
pub mod source;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PkgError {
pub code: &'static str,
pub message: String,
}
impl PkgError {
pub fn new(code: &'static str, message: impl Into<String>) -> Self {
PkgError {
code,
message: message.into(),
}
}
pub fn io(path: &std::path::Path, err: impl fmt::Display) -> Self {
PkgError::new(
crate::diagnostics::codes::PKG_IO,
format!("{}: {}", path.display(), err),
)
}
}
impl fmt::Display for PkgError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "error[{}]: {}", self.code, self.message)
}
}
impl std::error::Error for PkgError {}
pub type PkgResult<T> = Result<T, PkgError>;