1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*******************************************************************************
*
* Copyright (c) 2025 - 2026 Haixing Hu.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0.
*
******************************************************************************/
//! # Dynamic Error Object
//!
//! Defines the shared dynamic error object bounds used by boxed errors.
//!
//! `DynError` names the trait object behind [`super::BoxError`]. Keeping the
//! bounds in one alias avoids repeating `dyn Error + Send + Sync + 'static`
//! across callback signatures and source-error storage fields.
//!
//! Most APIs should use [`super::BoxError`] for owned errors. Use `DynError`
//! directly when the error is borrowed behind another pointer or reference.
//!
use Error;
/// Dynamic error trait object used by shared boxed error helpers.
///
/// The object is `Send`, `Sync`, and `'static` so it can be moved across
/// thread and async task boundaries.
///
/// # Design Rationale
///
/// Error trait objects are dynamically sized, so they must be accessed behind a
/// pointer such as `&`, `Box`, or `Arc`. This alias captures the project-wide
/// bounds for type-erased errors:
///
/// - `Send` allows the error object to cross thread and task boundaries.
/// - `Sync` allows shared references to the error object to be used safely.
/// - `'static` prevents borrowed context from being hidden inside stored errors.
///
/// # When to Use
///
/// Use `DynError` when an API needs to accept or inspect a borrowed dynamic
/// error object without taking ownership. For owned error values, prefer
/// [`super::BoxError`].
///
/// # Examples
///
/// ```rust
/// use std::io;
///
/// use qubit_error::error::DynError;
///
/// fn render_error(error: &DynError) -> String {
/// format!("operation failed: {error}")
/// }
///
/// let error = io::Error::other("disk is full");
/// assert_eq!(render_error(&error), "operation failed: disk is full");
/// ```
pub type DynError = dyn Error + Send + Sync + 'static;