Skip to main content

moirai_core/
lib.rs

1//! # Moirai Core
2//!
3//! Core abstractions and traits for the Moirai concurrency library.
4//!
5//! This crate provides the fundamental building blocks that all other
6//! Moirai crates build upon, including task abstractions, executor traits,
7//! and scheduling interfaces.
8
9#![deny(missing_docs)]
10#![cfg_attr(not(feature = "std"), no_std)]
11#![warn(missing_docs)]
12#![allow(clippy::module_name_repetitions)]
13#![allow(clippy::new_without_default)]
14#![allow(clippy::len_without_is_empty)]
15#![allow(clippy::borrowed_box)]
16#![allow(clippy::new_ret_no_self)]
17
18#[cfg(not(feature = "std"))]
19extern crate alloc;
20
21// Platform abstraction layer
22pub mod platform;
23
24// Core modules
25pub mod error;
26pub mod executor;
27pub mod memory;
28pub mod pool;
29pub mod scheduler;
30pub mod task;
31
32// Unified channel implementation
33#[cfg(feature = "std")]
34pub mod channel;
35
36// CacheAligned is imported from moirai-utils
37
38#[cfg(feature = "coroutine")]
39pub mod coroutine;
40
41#[cfg(feature = "std")]
42pub mod communication;
43
44#[cfg(all(any(unix, windows), feature = "std"))]
45pub mod ipc;
46
47// Core type definitions
48pub use error::{ExecutorError, PlacementFailure, SchedulerError, TaskError};
49pub use executor::{ExecutorConfig, TaskManager, TaskSpawner, TaskStatus, WorkerPlacement};
50pub use scheduler::SchedulerId;
51pub use task::{Priority, Task, TaskBuilder, TaskContext, TaskExt, TaskFuture, TaskHandle, TaskId};
52
53// `channel::unbounded` is deliberately not re-exported here or in `prelude`:
54// an unbounded queue turns a slow consumer into unbounded memory growth, so
55// the short, discoverable names stay bounded and the unbounded constructor is
56// reachable only through its fully qualified path.
57#[cfg(feature = "std")]
58pub use channel::{
59    Channel, ChannelConfig, ChannelError, ChannelStatistics, Consumer, DEFAULT_CHANNEL_CAPACITY,
60    MpmcChannel, MpmcReceiver, MpmcSender, Producer, Select, SpscConsumer, SpscProducer,
61    SpscReceiver, SpscRing, SpscSender, UnifiedReceiver, UnifiedSender, mpmc, spsc,
62    unified_channel, unified_channel_with_config,
63};
64
65// Re-export CacheAligned from moirai-utils for convenience
66pub use moirai_utils::CacheAligned;
67
68#[cfg(feature = "coroutine")]
69pub use coroutine::{
70    Coroutine, CoroutineExt, CoroutineFuture, CoroutineIterator, CoroutineResult, CoroutineState,
71    FunctionCoroutine,
72};
73
74// Re-export platform types for convenience
75pub use platform::{Arc, Box, String, Vec};
76
77/// Type alias for boxed errors.
78pub type BoxError = Box<dyn core::error::Error + Send + Sync>;
79
80/// Type alias for results with boxed errors.
81pub type Result<T> = core::result::Result<T, BoxError>;
82
83/// Prelude module for convenient imports.
84pub mod prelude {
85    pub use crate::{
86        ExecutorError, Priority, SchedulerError, SchedulerId, Task, TaskContext, TaskError,
87        TaskExt, TaskFuture, TaskId, TaskManager, TaskSpawner, TaskStatus,
88    };
89
90    #[cfg(feature = "std")]
91    pub use crate::{
92        Channel, ChannelError, Consumer, DEFAULT_CHANNEL_CAPACITY, MpmcReceiver, MpmcSender,
93        Producer, SpscConsumer, SpscProducer, SpscReceiver, SpscRing, SpscSender, mpmc, spsc,
94    };
95}