qubit_executor/service/rejected_execution.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9use std::{
10 io,
11 sync::Arc,
12};
13
14use thiserror::Error;
15
16/// Error returned when an executor service refuses to accept a task.
17///
18/// This error is about task acceptance only. It does not describe task
19/// execution success or failure; accepted tasks report their final result
20/// through the handle returned by the service.
21///
22/// # Author
23///
24/// Haixing Hu
25#[derive(Debug, Clone, Error)]
26pub enum RejectedExecution {
27 /// The service has been shut down and no longer accepts new tasks.
28 #[error("task rejected because the executor service is shut down")]
29 Shutdown,
30
31 /// The service is saturated and cannot accept more tasks.
32 #[error("task rejected because the executor service is saturated")]
33 Saturated,
34
35 /// The service accepted the task conceptually but could not create the
36 /// worker thread required to execute it.
37 #[error("task rejected because the executor service failed to spawn a worker: {source}")]
38 WorkerSpawnFailed {
39 /// I/O error reported while spawning the worker.
40 source: Arc<io::Error>,
41 },
42}
43
44impl PartialEq for RejectedExecution {
45 /// Compares rejection categories.
46 ///
47 /// Worker spawn failures compare equal by variant because [`io::Error`]
48 /// does not provide value equality.
49 ///
50 /// # Parameters
51 ///
52 /// * `other` - Rejection value to compare with this value.
53 ///
54 /// # Returns
55 ///
56 /// `true` when both values have the same rejection category.
57 fn eq(&self, other: &Self) -> bool {
58 matches!(
59 (self, other),
60 (Self::Shutdown, Self::Shutdown)
61 | (Self::Saturated, Self::Saturated)
62 | (
63 Self::WorkerSpawnFailed { .. },
64 Self::WorkerSpawnFailed { .. }
65 )
66 )
67 }
68}
69
70impl Eq for RejectedExecution {}