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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
*
* Copyright (c) 2025 - 2026 Haixing Hu.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0.
*
******************************************************************************/
//! # Boxed Error Result
//!
//! Defines the result alias for operations that intentionally return boxed
//! dynamic errors.
//!
//! `BoxResult<T>` is a concise spelling of `Result<T, BoxError>` for examples,
//! callbacks, and integration helpers that combine unrelated error types.
//!
use BoxError;
/// Result alias using [`BoxError`] as the error type.
///
/// This is primarily useful for examples, callbacks, integration glue, and
/// internal helpers that combine several unrelated error types.
///
/// # Design Rationale
///
/// A repeated `Result<T, BoxError>` signature is noisy in higher-order APIs.
/// This alias keeps those signatures focused on the successful value while
/// still making the erased error type explicit through the `Box` prefix.
///
/// `BoxResult<T>` intentionally has only one type parameter. If an API should
/// preserve a caller-provided error type, write `Result<T, E>` directly instead
/// of hiding `E` behind a boxed trait object.
///
/// # When to Use
///
/// Use `BoxResult<T>` when every failure path can be treated uniformly as a
/// type-erased source error, especially in:
///
/// - examples and small executable entry points;
/// - callback return types;
/// - internal orchestration that combines file, parse, and configuration
/// errors without structured recovery.
///
/// Avoid it for domain APIs that should expose a concrete error enum.
///
/// # Examples
///
/// Combining unrelated error types with `?`:
///
/// ```rust
/// use std::fs;
///
/// use qubit_error::error::BoxResult;
///
/// fn read_port(path: &str) -> BoxResult<u16> {
/// let content = fs::read_to_string(path)?;
/// let port = content.trim().parse::<u16>()?;
/// Ok(port)
/// }
/// ```
///
/// Using `BoxResult` in a callback-oriented helper:
///
/// ```rust
/// use qubit_error::error::BoxResult;
///
/// fn run_task<F>(task: F) -> BoxResult<usize>
/// where
/// F: FnOnce() -> BoxResult<usize>,
/// {
/// task()
/// }
///
/// let value = run_task(|| Ok(42)).expect("task should succeed");
/// assert_eq!(value, 42);
/// ```
pub type BoxResult<T> = ;