Skip to main content

wrap_internal_err

Macro wrap_internal_err 

Source
macro_rules! wrap_internal_err {
    ($($err:ty),+ $(,)? => $target:ident::$variant:ident) => { ... };
}
Expand description

Wires up low-level standard library errors directly into your domain-specific error enums.

This macro generates the From implementations required to bypass the “double-from” limitation of the ? operator. It automatically intercepts specific errors (like TryFromIntError) and wraps them in your target domain’s Internal error variant.

§Example

use std::num::TryFromIntError;
use std::time::SystemTimeError;
// Assuming your crate is named `webdav_server`
use webdav_server::error::internal::Error as InternalErr;
use webdav_server::wrap_internal_err;

#[derive(thiserror::Error, Debug)]
pub enum StorageError {
    // thiserror handles the immediate InternalErr -> StorageError conversion
    #[error(transparent)]
    Internal(#[from] InternalErr),
}

// This macro generates the TryFromIntError -> InternalErr -> StorageError conversions!
wrap_internal_err! {
    TryFromIntError,
    SystemTimeError
    => StorageError::Internal
}

// Now you can use `?` on infallible casts in functions returning Result<T, StorageError>