Skip to main content

TempsError

Enum TempsError 

Source
pub enum TempsError {
    ParseError {
        message: String,
        input: String,
        position: Option<usize>,
    },
    DateCalculationError {
        message: String,
        context: Option<String>,
    },
    InvalidDate {
        year: u16,
        month: u8,
        day: u8,
    },
    InvalidTime {
        hour: u8,
        minute: u8,
        second: u8,
    },
    InvalidTimezoneOffset {
        hours: i8,
        minutes: u8,
    },
    AmbiguousTime {
        message: String,
    },
    ArithmeticOverflow {
        operation: String,
    },
    UnsupportedOperation {
        operation: String,
    },
    BackendError {
        message: String,
        backend: String,
    },
}
Expand description

The main error type for the temps library.

This enum represents all possible errors that can occur during parsing and time calculation operations.

Variants§

§

ParseError

Error that occurs during parsing of time expressions.

This error is returned when the input string cannot be parsed as a valid time expression in the specified language.

§Example

use temps_core::TempsError;

let err = TempsError::parse_error("Unrecognized time unit", "in 5 blargs");

Fields

§message: String

The specific parsing error message

§input: String

The input that failed to parse

§position: Option<usize>

Optional position in the input where parsing failed

§

DateCalculationError

Error that occurs during date/time calculations.

This error is returned when date arithmetic operations fail, such as when adding months to January 31st would result in February 31st (which doesn’t exist).

§Example

use temps_core::TempsError;

let err = TempsError::date_calculation("Month overflow");

Fields

§message: String

The specific calculation error message

§context: Option<String>

Optional context about what caused the error

§

InvalidDate

Error for invalid date components

Fields

§year: u16

The year component

§month: u8

The month component (1-12)

§day: u8

The day component (1-31)

§

InvalidTime

Error for invalid time components

Fields

§hour: u8

The hour component (0-23)

§minute: u8

The minute component (0-59)

§second: u8

The second component (0-59)

§

InvalidTimezoneOffset

Error for invalid timezone offset

Fields

§hours: i8

The hour offset (-12 to +14)

§minutes: u8

The minute offset (0-59)

§

AmbiguousTime

Error for ambiguous local time (e.g., during DST transitions)

Fields

§message: String

Description of the ambiguity

§

ArithmeticOverflow

Error for arithmetic overflow in date calculations

Fields

§operation: String

The operation that caused the overflow

§

UnsupportedOperation

Error for unsupported operations

Fields

§operation: String

Description of the unsupported operation

§

BackendError

Error from the underlying datetime backend (chrono, jiff, etc.)

Fields

§message: String

The error message from the backend

§backend: String

The backend that produced the error

Implementations§

Source§

impl TempsError

Source

pub fn parse_error(message: impl Into<String>, input: impl Into<String>) -> Self

Creates a new parse error without position information.

Use this when you know parsing failed but don’t have a specific position in the input where the error occurred.

§Arguments
  • message - Description of what went wrong
  • input - The input string that failed to parse
§Example
use temps_core::TempsError;

let err = TempsError::parse_error(
    "Expected time unit",
    "in 5"
);
Source

pub fn parse_error_with_position( message: impl Into<String>, input: impl Into<String>, position: usize, ) -> Self

Creates a new parse error with position information.

Use this when you know exactly where in the input the parse error occurred.

§Arguments
  • message - Description of what went wrong
  • input - The input string that failed to parse
  • position - Character position where parsing failed
§Example
use temps_core::TempsError;

let err = TempsError::parse_error_with_position(
    "Unexpected character",
    "in 5 minuts",
    9  // Points to the 't' in "minuts"
);
Source

pub fn date_calculation(message: impl Into<String>) -> Self

Creates a new date calculation error.

Use this for errors that occur during date arithmetic operations.

§Example
use temps_core::TempsError;

let err = TempsError::date_calculation(
    "Cannot subtract 13 months from January"
);
Source

pub fn date_calculation_with_source( message: impl Into<String>, context: impl Into<String>, ) -> Self

Creates a new date calculation error with additional context.

Use this when you want to include information about what caused the calculation to fail (e.g., an error from the backend library).

§Example
use temps_core::TempsError;

let err = TempsError::date_calculation_with_source(
    "Failed to add months",
    "chronos error: date out of range"
);
Source

pub fn invalid_date(year: u16, month: u8, day: u8) -> Self

Creates an invalid date error

Source

pub fn invalid_time(hour: u8, minute: u8, second: u8) -> Self

Creates an invalid time error

Source

pub fn invalid_timezone_offset(hours: i8, minutes: u8) -> Self

Creates an invalid timezone offset error

Source

pub fn ambiguous_time(message: impl Into<String>) -> Self

Creates an ambiguous time error

Source

pub fn arithmetic_overflow(operation: impl Into<String>) -> Self

Creates an arithmetic overflow error

Source

pub fn unsupported_operation(operation: impl Into<String>) -> Self

Creates an unsupported operation error

Source

pub fn backend_error( message: impl Into<String>, backend: impl Into<String>, ) -> Self

Creates a backend error

Trait Implementations§

Source§

impl Clone for TempsError

Source§

fn clone(&self) -> TempsError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TempsError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TempsError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for TempsError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl Hash for TempsError

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TempsError

Source§

fn eq(&self, other: &TempsError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TempsError

Source§

impl StructuralPartialEq for TempsError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.