rsgt 0.3.5

Rust simple GUI Toolkit
//! # Error handling

use std::fmt;
use std::fmt::Debug;

pub struct RSGTError {
    error: _RSGTError,
}

impl RSGTError {
    pub fn illegal_argument(str: impl Into<String>) -> Self {
        Self {
            error: _RSGTError::IllegalArgument(str.into()),
        }
    }
}

enum _RSGTError {
    IllegalArgument(String),
}

impl _RSGTError {
    pub fn description(&self) -> &str {
        match self {
            _RSGTError::IllegalArgument(s) => s.as_str(),
        }
    }
}

impl fmt::Display for RSGTError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match &self.error {
            _RSGTError::IllegalArgument(s) => f.write_str(s),
        }
    }
}

impl Debug for RSGTError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_fmt(format_args!("{}", self.error.description()))
    }
}