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
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
InvalidDate
Error for invalid date components
Fields
InvalidTime
Error for invalid time components
Fields
InvalidTimezoneOffset
Error for invalid timezone offset
AmbiguousTime
Error for ambiguous local time (e.g., during DST transitions)
ArithmeticOverflow
Error for arithmetic overflow in date calculations
UnsupportedOperation
Error for unsupported operations
BackendError
Error from the underlying datetime backend (chrono, jiff, etc.)
Implementations§
Source§impl TempsError
impl TempsError
Sourcepub fn parse_error(message: impl Into<String>, input: impl Into<String>) -> Self
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 wronginput- The input string that failed to parse
§Example
use temps_core::TempsError;
let err = TempsError::parse_error(
"Expected time unit",
"in 5"
);Sourcepub fn parse_error_with_position(
message: impl Into<String>,
input: impl Into<String>,
position: usize,
) -> Self
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 wronginput- The input string that failed to parseposition- 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"
);Sourcepub fn date_calculation(message: impl Into<String>) -> Self
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"
);Sourcepub fn date_calculation_with_source(
message: impl Into<String>,
context: impl Into<String>,
) -> Self
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"
);Sourcepub fn invalid_date(year: u16, month: u8, day: u8) -> Self
pub fn invalid_date(year: u16, month: u8, day: u8) -> Self
Creates an invalid date error
Sourcepub fn invalid_time(hour: u8, minute: u8, second: u8) -> Self
pub fn invalid_time(hour: u8, minute: u8, second: u8) -> Self
Creates an invalid time error
Sourcepub fn invalid_timezone_offset(hours: i8, minutes: u8) -> Self
pub fn invalid_timezone_offset(hours: i8, minutes: u8) -> Self
Creates an invalid timezone offset error
Sourcepub fn ambiguous_time(message: impl Into<String>) -> Self
pub fn ambiguous_time(message: impl Into<String>) -> Self
Creates an ambiguous time error
Sourcepub fn arithmetic_overflow(operation: impl Into<String>) -> Self
pub fn arithmetic_overflow(operation: impl Into<String>) -> Self
Creates an arithmetic overflow error
Sourcepub fn unsupported_operation(operation: impl Into<String>) -> Self
pub fn unsupported_operation(operation: impl Into<String>) -> Self
Creates an unsupported operation error
Trait Implementations§
Source§impl Clone for TempsError
impl Clone for TempsError
Source§fn clone(&self) -> TempsError
fn clone(&self) -> TempsError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TempsError
impl Debug for TempsError
Source§impl Display for TempsError
impl Display for TempsError
Source§impl Error for TempsError
impl Error for TempsError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl Hash for TempsError
impl Hash for TempsError
Source§impl PartialEq for TempsError
impl PartialEq for TempsError
Source§fn eq(&self, other: &TempsError) -> bool
fn eq(&self, other: &TempsError) -> bool
self and other values to be equal, and is used by ==.impl Eq for TempsError
impl StructuralPartialEq for TempsError
Auto Trait Implementations§
impl Freeze for TempsError
impl RefUnwindSafe for TempsError
impl Send for TempsError
impl Sync for TempsError
impl Unpin for TempsError
impl UnsafeUnpin for TempsError
impl UnwindSafe for TempsError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
Source§impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
Source§fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
WrappingSpan::make_wrapped to wrap an AST node in a span.