rstime 0.1.0

A zero-dependency Rust time library providing date, time, datetime types with formatting, parsing, Unix timestamps, and clock functionality.
Documentation
//! Error type module
//!
//! Provides [`RstimeError`] for all rstime operations.

use std::fmt;

/// Error type for rstime operations
///
/// Returned by parsing, construction, and arithmetic functions.
///
/// # Examples
///
/// ```rust
/// use rstime::RstimeError;
///
/// let err = RstimeError::new("invalid date");
/// assert_eq!(err.to_string(), "invalid date");
/// ```
#[derive(Clone, Debug, PartialEq)]
pub struct RstimeError {
    message: String,
}

impl RstimeError {
    /// Create a new error with a message
    pub fn new<M: Into<String>>(msg: M) -> Self {
        RstimeError { message: msg.into() }
    }

    /// Returns the error message
    pub fn message(&self) -> &str {
        &self.message
    }
}

impl fmt::Display for RstimeError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.message)
    }
}

impl std::error::Error for RstimeError {}

/// Convenience alias for `Result<T, RstimeError>`
pub type RstimeResult<T> = Result<T, RstimeError>;