Skip to main content

ContractSource

Struct ContractSource 

Source
pub struct ContractSource { /* private fields */ }
Expand description

Preserves the complete original error while keeping the report Send + Sync.

Some filesystem errors own a recovery writer that is Send but not Sync. This wrapper serializes explicit inspection and ownership transfer. Formatting never invokes provider code. Taking the source transfers any recovery responsibility; otherwise ordinary destruction still drops it.

§Examples

A run returned by FileSystemContractSuite::run exposes failures through ContractRun::failures. A failed owned write may retain this wrapper in the failure’s standard error source chain. Taking the source transfers the provider error and any recovery responsibility:

use std::error::Error;

use qubit_fs_testkit::ContractRun;
use qubit_fs_testkit::ContractSource;

fn take_owned_source(run: &ContractRun) -> Option<Box<dyn Error + Send>> {
    let failure = run.failures().first()?;
    Error::source(failure)?
        .downcast_ref::<ContractSource>()?
        .take()
}

Implementations§

Source§

impl ContractSource

Source

pub fn inspect<T>( &self, inspect: impl FnOnce(&(dyn Error + Send + 'static)) -> T, ) -> Option<T>

Inspects the original concrete error while it remains owned by the run.

The callback runs synchronously while this source’s mutex is held. It must not directly or indirectly call inspect or take on the same source, or wait for another operation that needs that mutex. Return the inspection result first, then call take outside the callback.

use std::error::Error;

use qubit_fs_testkit::ContractSource;

fn take_io_source(source: &ContractSource) -> Option<Box<dyn Error + Send>> {
    let is_io_error = source.inspect(|error| error.is::<std::io::Error>())?;
    if is_io_error { source.take() } else { None }
}

Inspection and transfer are not atomic. Another caller may take the source between these operations, so callers must handle take() == None. Taking the source also transfers explicit recovery responsibility to the caller.

§Type Parameters
  • T: The result produced by the caller’s inspection callback.
§Parameters
  • inspect: A synchronous callback that inspects the retained error while the source mutex is held.
§Returns

Returns Some with the result of inspect while the source is retained. Returns None after a caller has taken ownership of the source.

Source

pub fn take(&self) -> Option<Box<dyn Error + Send>>

Transfers the original error and any recovery handle to the caller.

The caller becomes responsible for its explicit recovery or disposal.

§Returns

The original error if it is still retained, or None if another caller has already taken it.

Trait Implementations§

Source§

impl Debug for ContractSource

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult

Formats a stable summary without invoking the retained provider error.

§Parameters
  • formatter: Destination for the stable source summary.
Source§

impl Display for ContractSource

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult

Formats recovery guidance without exposing provider-specific details.

§Parameters
  • formatter: Destination for the recovery guidance.
Source§

impl Error for ContractSource

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

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> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.