jiff::error

Struct Error

Source
pub struct Error {
    inner: Option<Arc<ErrorInner>>,
}
Expand description

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 no introspection capabilities.

§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.

Fields§

§inner: Option<Arc<ErrorInner>>

The internal representation of an error.

This is in an Arc to make an Error cloneable. It could otherwise be automatically cloneable, but it embeds a std::io::Error when the std feature is enabled, which isn’t cloneable.

This also makes clones cheap. And it also make the size of error equal to one word (although a Box would achieve that last goal). This is why we put the Arc here instead of on std::io::Error directly.

Implementations§

Source§

impl Error

Source

pub(crate) fn adhoc<'a>(message: impl Display + 'a) -> Error

Creates a new “ad hoc” error value.

An ad hoc error value is just an opaque string. In theory we should avoid creating such error values, but in practice, they are extremely convenient. And the alternative is quite brutal given the varied ways in which things in a datetime library can fail. (Especially parsing errors.)

Source

pub(crate) fn adhoc_from_args<'a>(message: Arguments<'a>) -> Error

Like Error::adhoc, but accepts a core::fmt::Arguments.

This is used with the err! macro so that we can thread a core::fmt::Arguments down. This lets us extract a &'static str from some messages in core-only mode and provide somewhat decent error messages in some cases.

Source

pub(crate) fn adhoc_from_static_str(message: &'static str) -> Error

Like Error::adhoc, but creates an error from a &'static str directly.

This is useful in contexts where you know you have a &'static str, and avoids relying on alloc-only routines like Error::adhoc.

Source

pub(crate) fn range( what: &'static str, given: impl Into<i128>, min: impl Into<i128>, max: impl Into<i128>, ) -> Error

Creates a new error indicating that a given value is out of the specified min..=max range. The given what label is used in the error message as a human readable description of what exactly is out of range. (e.g., “seconds”)

Source

pub(crate) fn shared(err: SharedError) -> Error

Creates a new error from the special “shared” error type.

Source

pub(crate) fn io(err: Error) -> Error

A convenience constructor for building an I/O error.

This returns an error that is just a simple wrapper around the std::io::Error type. In general, callers should alwasys attach some kind of context to this error (like a file path).

This is only available when the std feature is enabled.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

Returns a copy 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 Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

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 ErrorContext for Error

Source§

fn context(self, consequent: impl IntoError) -> Error

Contextualize the given consequent error with this (self) error as the cause. Read more
Source§

fn with_context<E: IntoError>(self, consequent: impl FnOnce() -> E) -> Error

Like context, but hides error construction within a closure. Read more
Source§

impl From<ErrorKind> for Error

Source§

fn from(kind: ErrorKind) -> Error

Converts to this type from the input type.
Source§

impl IntoError for Error

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe for Error

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.