Skip to main content

medi_rs/
error.rs

1//! Errors returned by mediator lifecycle and typed event queue operations.
2
3/// Error returned when a mediator is started more than once.
4///
5/// A mediator starts its generated event workers and `#[medi_task]` tasks at
6/// most once. Check `is_started` before calling `start` when needed.
7#[derive(Debug, Clone, Copy, Eq, PartialEq)]
8pub enum StartError {
9    /// The mediator has already started its generated workers and tasks.
10    AlreadyStarted,
11}
12
13/// Error returned by a non-blocking event publish attempt.
14///
15/// The event is returned so callers can retry, persist, or discard it.
16#[derive(Debug, Eq, PartialEq)]
17pub enum TryPublishError<T> {
18    /// The bounded queue has no available capacity.
19    Full(T),
20    /// The mediator is shutting down or its event worker is unavailable.
21    Closed(T),
22}
23
24/// Framework error for queue operations.
25#[derive(Debug, Clone, Copy, Eq, PartialEq)]
26pub enum Error {
27    /// An event could not be enqueued because the queue is closed.
28    EventPublishingError,
29    /// An event worker could not receive another event.
30    EventProcessingError,
31}
32
33/// Framework result used by event publishing and queue operations.
34pub type Result<T> = core::result::Result<T, Error>;