refactor(core): reorganize module structure
This commit is contained in:
parent
59ab96be98
commit
a6c1863f57
22 changed files with 231 additions and 164 deletions
49
core/src/error.rs
Normal file
49
core/src/error.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// src/error.rs
|
||||
//
|
||||
// Central error and result types for noctua_core.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// A requested file or resource was not found.
|
||||
NotFound(String),
|
||||
/// The file format or operation is not supported.
|
||||
Unsupported(String),
|
||||
/// A rendering operation failed.
|
||||
Render(String),
|
||||
/// A session could not be loaded or saved.
|
||||
Session(String),
|
||||
/// An underlying I/O error.
|
||||
Io(std::io::Error),
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Error::NotFound(msg) => write!(f, "Not found: {msg}"),
|
||||
Error::Unsupported(msg) => write!(f, "Unsupported: {msg}"),
|
||||
Error::Render(msg) => write!(f, "Render error: {msg}"),
|
||||
Error::Session(msg) => write!(f, "Session error: {msg}"),
|
||||
Error::Io(err) => write!(f, "I/O error: {err}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Error::Io(err) => Some(err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Error::Io(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue