Skip to main content

bombay_framework/
lib.rs

1//! Application-facing composition for the bombay local runtime.
2//!
3//! This crate adds no runtime machinery. Its prelude selects the public pieces
4//! needed to author and run local actors while Bombay Behavior and bombay
5//! retain ownership of their respective algebra and runtime contracts.
6
7/// Construct the existing local [`bombay::System`] with named semantic
8/// inputs while preserving the concrete router type.
9///
10/// This macro expands directly to [`bombay::System::new`]; it creates no
11/// alternate runtime, spawn path, task, registry, or policy object.
12///
13/// ```
14/// use bombay_framework::{local_system, prelude::*};
15///
16/// let _: System<AddressRouter<MailAddr, ()>> = local_system!(
17///     mailbox = MailboxConfig::bounded(8),
18///     routes = AddressRouter::default(),
19/// );
20/// ```
21///
22/// Named inputs intentionally reject misspellings at the authoring boundary:
23///
24/// ```compile_fail
25/// use bombay_framework::{local_system, prelude::*};
26///
27/// let _ = local_system!(
28///     capacity = MailboxConfig::bounded(8),
29///     routes = AddressRouter::<MailAddr, ()>::default(),
30/// );
31/// ```
32#[macro_export]
33macro_rules! local_system {
34    (mailbox = $mailbox:expr, routes = $routes:expr $(,)?) => {
35        $crate::prelude::System::new($mailbox, $routes)
36    };
37}
38
39/// The local application authoring surface.
40pub mod prelude {
41    pub use crate::local_system;
42    pub use bombay::behavior;
43    pub use bombay::behavior::{
44        Actions, Address, Behavior, BehaviorFn, Births, Compose, Crash, Create, Deadline, Delivery,
45        Exit, Handler, MailAddr, Never, NoBirths, Proxy, ProxyCommand, Pure, ReceiveTimeout,
46        Recipient, RestartPolicy, SendProduct, ServiceSends, Step, StopOnShutdown, Strategy,
47        SupervisionEvent, Supervisor, User, Watch, WorkerStopped,
48    };
49    pub use bombay::{
50        ActorRef, AddressInUse, AddressRouter, DeliveryRouter, EndpointRegistry,
51        IncarnationEndpoint, MailboxAnchor, MailboxConfig, RunExit, System, TaskOutcome,
52    };
53}
54
55#[cfg(test)]
56mod tests {
57    use super::prelude::*;
58
59    #[test]
60    fn prelude_selects_the_existing_runtime_types() {
61        fn same_type<T>(_: &T, _: &T) {}
62
63        let direct: System<AddressRouter<MailAddr, ()>> =
64            System::new(MailboxConfig::bounded(8), AddressRouter::default());
65        let facade: System<AddressRouter<MailAddr, ()>> = local_system!(
66            mailbox = MailboxConfig::bounded(8),
67            routes = AddressRouter::default(),
68        );
69        same_type(&direct, &facade);
70    }
71}