diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-22 22:10:19 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-17 21:02:05 +0800 |
| commit | 5a5a07c7fad31641d032a743e4e87ffb58ade17d (patch) | |
| tree | b6fbd33e8de82e5f9d9e6b99e3cb2102e47fe3ee /rola-vcs/src/err.rs | |
Initial commitmain
Diffstat (limited to 'rola-vcs/src/err.rs')
| -rw-r--r-- | rola-vcs/src/err.rs | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/rola-vcs/src/err.rs b/rola-vcs/src/err.rs new file mode 100644 index 0000000..71e0a34 --- /dev/null +++ b/rola-vcs/src/err.rs @@ -0,0 +1,105 @@ +//! Error +//! +//! This module is used to create and log Rorolala standard errors + +use std::{ + fmt::{Display, Formatter}, + io::Error as IoError, +}; + +mod io; + +/// Rorolala standard error +#[derive(Default)] +pub struct RolaError { + pub module: RolaModule, + pub data: RolaErrorData, + pub message: String, +} + +/// Rorolala module, used to locate the source of an error +#[derive(Debug, Eq, Default)] +#[repr(u8)] +pub enum RolaModule { + #[default] + Empty, + + Bucket, + Workdraft, +} + +/// Error data +#[derive(Debug, Default)] +pub enum RolaErrorData { + #[default] + Empty, + + /// IO error + IO(IoError), +} + +impl RolaError { + /// Create a new RolaError + pub fn new(module: RolaModule, data: RolaErrorData, message: String) -> Self { + Self { + module, + data, + message, + } + } + + /// Create an empty RolaError + pub fn empty() -> Self { + Self { + module: RolaModule::Empty, + data: RolaErrorData::Empty, + message: String::new(), + } + } + + /// Set the module + pub fn with_module(mut self, module: RolaModule) -> Self { + self.module = module; + self + } + + /// Set the message + pub fn with_message(mut self, message: String) -> Self { + self.message = message; + self + } + + /// Set the error data + pub fn with_data(mut self, data: RolaErrorData) -> Self { + self.data = data; + self + } +} + +impl Display for RolaError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.message) + } +} + +impl PartialEq for RolaError { + fn eq(&self, other: &Self) -> bool { + self.message == other.message && self.module == other.module + } +} + +impl Display for RolaModule { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + +impl PartialEq for RolaModule { + fn eq(&self, other: &Self) -> bool { + matches!( + (self, other), + (RolaModule::Bucket, RolaModule::Bucket) + | (RolaModule::Workdraft, RolaModule::Workdraft) + ) + } +} |
