Skip to main content

strided_exec/
error.rs

1//! Error types of the crate.
2
3/// Failure to build a [`Pool`](crate::Pool) or an [`Exec`](crate::Exec).
4///
5/// The enum is `#[non_exhaustive]`: new refusals may be added in a minor
6/// release, so match with a wildcard arm.
7///
8/// # Examples
9///
10/// ```
11/// use strided_exec::{Error, Exec, Pool};
12///
13/// let pool = Pool::builder().threads(1).build()?;
14/// assert_eq!(Exec::new(&pool, 0).unwrap_err(), Error::ZeroBudget);
15/// # Ok::<(), Error>(())
16/// ```
17#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
18#[non_exhaustive]
19pub enum Error {
20    /// A token was requested with a budget of zero slots.
21    #[error("an execution budget must be at least one slot")]
22    ZeroBudget,
23    /// A pool was requested with zero worker threads.
24    #[error("a pool needs at least one worker thread")]
25    ZeroThreads,
26    /// The operating system or the scheduler refused to start the workers.
27    #[error("failed to start the pool workers: {0}")]
28    PoolBuild(String),
29}
30
31/// A [`broadcast`](crate::Exec::broadcast) that cannot guarantee co-scheduling.
32///
33/// Nothing was run when this is returned. The caller falls back to a kernel
34/// that does not need all participants at once.
35///
36/// # Examples
37///
38/// ```
39/// use strided_exec::Refused;
40///
41/// assert!(Refused::ForkChild.to_string().contains("fork"));
42/// ```
43#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
44#[non_exhaustive]
45pub enum Refused {
46    /// The token was produced by [`fork`](crate::Exec::fork) (or by a
47    /// [`reborrow`](crate::Exec::reborrow) of such a token): its slots may share
48    /// workers with sibling tasks, so its participants could wait on each other.
49    #[error("the token is a child produced by fork; its slots may share workers with siblings")]
50    ForkChild,
51    /// The caller is already a worker of the token's pool, so it would occupy
52    /// one of the slots the participants need.
53    #[error("the caller is a worker of the token's pool and would occupy a participant slot")]
54    CallerInPool,
55}