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
impl ContractSource
Sourcepub fn inspect<T>(
&self,
inspect: impl FnOnce(&(dyn Error + Send + 'static)) -> T,
) -> Option<T>
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.
Trait Implementations§
Source§impl Debug for ContractSource
impl Debug for ContractSource
Source§impl Display for ContractSource
impl Display for ContractSource
Source§impl Error for ContractSource
impl Error for ContractSource
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()