Struct Error
pub struct Error { /* private fields */ }
An error that can occur in this crate.
The most common type of error is a result of overflow. But other errors exist as well:
- Time zone database lookup failure.
- Configuration problem. (For example, trying to round a span with calendar units without providing a relative datetime.)
- An I/O error as a result of trying to open a time zone database from a
directory via
TimeZoneDatabase::from_dir. - Parse errors.
Introspection is limited
Other than implementing the std::error::Error trait when the
std feature is enabled, the core::fmt::Debug trait and the
core::fmt::Display trait, this error type currently provides
very limited introspection capabilities. Simple predicates like
Error::is_range are provided, but the predicates are not
exhaustive. That is, there exist some errors that do not return
true for any of the Error::is_* predicates.
Design
This crate follows the "One True God Error Type Pattern," where only one error type exists for a variety of different operations. This design was chosen after attempting to provide finer grained error types. But finer grained error types proved difficult in the face of composition.
More about this design choice can be found in a GitHub issue about error types.
Implementations
impl Error
fn from_args<'a>(message: Arguments<'a>) -> ErrorCreates a new error value from
core::fmt::Arguments.It is expected to use
format_args!from Rust's standard library (available incore) to create acore::fmt::Arguments.Callers should generally use their own error types. But in some circumstances, it can be convenient to manufacture a Jiff error value specifically.
Core-only environments
In core-only environments without a dynamic memory allocator, error messages may be degraded in some cases. For example, if the given
core::fmt::Argumentscould not be converted to a simple borrowed&str, then this will ignore the input given and return an "unknown" Jiff error.Example
use Error; let err = from_args; assert_eq!;fn is_range(&self) -> boolReturns true when this error originated as a result of a value being out of Jiff's supported range.
Example
use Date; assert!; assert!; assert!;fn is_invalid_parameter(&self) -> boolReturns true when this error originated as a result of an invalid configuration of parameters to a function call.
This particular error category is somewhat nebulous, but it's generally meant to cover errors that could have been statically prevented by Jiff with more types in its API. Instead, a smaller API is preferred.
Example: invalid rounding options
use ; let span = 44.seconds; let err = span.round.unwrap_err; // Rounding increments for seconds must divide evenly into `60`. // But `45` does not. Thus, this is a "configuration" error. assert!;Example: invalid units
One cannot round a span between dates to units less than days:
use ; let date1 = date; let date2 = date; let err = date1.until.unwrap_err; assert!;Similarly, one cannot round a span between times to units greater than hours:
use ; let time1 = time; let time2 = time; let err = time1.until.unwrap_err; assert!;fn is_crate_feature(&self) -> boolReturns true when this error originated as a result of an operation failing because an appropriate Jiff crate feature was not enabled.
Example
use jiff::tz::TimeZone; // This passes when the `tz-system` crate feature is NOT enabled. assert!(TimeZone::try_system().unwrap_err().is_crate_feature());
Trait Implementations
impl Clone for Error
fn clone(&self) -> Self
impl Debug for Error
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Display for Error
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Error for Error
Auto Trait Implementations
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Freeze for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
Blanket Implementations
impl<T> Any for Error
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Error
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Error
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Error
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Error
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Error
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> ToString for Error
where
T: Display + ?Sized,
fn to_string(&self) -> String
impl<T, U> Into<U> for Error
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Error
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Error
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>