1#[derive(Debug)]
3pub enum RosaceError {
4 NotFound { resource: &'static str },
6 InvalidState(String),
8 LayoutError(String),
10 Internal(String),
12}
13
14impl RosaceError {
15 pub fn not_found(resource: &'static str) -> Self {
17 RosaceError::NotFound { resource }
18 }
19
20 pub fn internal(msg: impl Into<String>) -> Self {
22 RosaceError::Internal(msg.into())
23 }
24}
25
26impl std::fmt::Display for RosaceError {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 match self {
29 RosaceError::NotFound { resource } => write!(f, "resource not found: {resource}"),
30 RosaceError::InvalidState(msg) => write!(f, "invalid state: {msg}"),
31 RosaceError::LayoutError(msg) => write!(f, "layout error: {msg}"),
32 RosaceError::Internal(msg) => write!(f, "internal error: {msg}"),
33 }
34 }
35}
36
37impl std::error::Error for RosaceError {}
38
39pub type RosaceResult<T> = Result<T, RosaceError>;