qubit_retry/error/attempt_executor_error.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! Attempt executor failure information.
11//!
12
13use std::error::Error;
14use std::fmt;
15
16use serde::{
17 Deserialize,
18 Serialize,
19};
20
21/// Failure produced by the retry executor before an attempt can run normally.
22///
23/// This type is used for infrastructure failures such as failing to spawn a
24/// worker thread for [`crate::Retry::run_in_worker`].
25#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
26pub struct AttemptExecutorError {
27 /// Human-readable executor failure message.
28 message: Box<str>,
29}
30
31impl AttemptExecutorError {
32 /// Creates an executor failure from a message.
33 ///
34 /// # Parameters
35 /// - `message`: Failure message to store.
36 ///
37 /// # Returns
38 /// An executor failure value.
39 #[inline]
40 pub fn new(message: &str) -> Self {
41 Self {
42 message: message.into(),
43 }
44 }
45
46 /// Returns the executor failure message.
47 ///
48 /// # Returns
49 /// Failure message text.
50 #[inline]
51 pub fn message(&self) -> &str {
52 &self.message
53 }
54}
55
56impl fmt::Display for AttemptExecutorError {
57 /// Formats the executor failure message.
58 ///
59 /// # Parameters
60 /// - `f`: Formatter provided by the standard formatting machinery.
61 ///
62 /// # Returns
63 /// Formatting result.
64 ///
65 /// # Errors
66 /// Returns a formatting error if the formatter rejects output.
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 f.write_str(&self.message)
69 }
70}
71
72impl Error for AttemptExecutorError {}