coralstack_cmd_ipc/lib.rs
1//! Rust port of [`@coralstack/cmd-ipc`](https://github.com/CoralStack/cmd-ipc).
2//!
3//! The wire protocol is byte-identical to the TypeScript library, so Rust
4//! and Node.js processes can exchange commands over any channel that
5//! carries JSON.
6//!
7//! This crate is runtime-agnostic: it depends on the `futures` primitives
8//! only, and does not pull in tokio, async-std, or smol. Users drive the
9//! per-channel pump future returned by `CommandRegistry::register_channel`
10//! with the executor of their choice.
11//!
12//! See [`message`] for the wire format, [`ttl_map`] for the storage
13//! primitive shared by the registry's reply/route/event tables, and
14//! [`macro@command`] / [`macro@command_service`] / [`macro@event`] /
15//! [`macro@payload`] for the attribute macros that let you register
16//! commands and events next to the code that implements them.
17
18pub mod channel;
19pub mod command;
20pub mod error;
21pub mod event;
22pub mod message;
23pub mod registry;
24pub mod schema;
25pub mod ttl_map;
26
27pub use channel::{CommandChannel, InMemoryChannel};
28pub use command::{BoxedDynCommand, BoxedHandler, Command, DynCommand};
29pub use error::{ChannelError, CommandError, ExecuteErrorCode, RegisterErrorCode};
30pub use event::{DynEvent, Event};
31pub use message::{
32 CommandDef, CommandSchema, ExecuteError, ExecuteResult, False, Message, MessageId,
33 RegisterResult, True,
34};
35pub use registry::{CommandRegistry, Config};
36
37pub use schema::normalize_schema;
38pub use ttl_map::TtlMap;
39
40// Re-exports for use by code generated by the `#[command]` /
41// `#[command_service]` / `#[event]` / `#[payload]` macros, AND for
42// convenience so user crates that only depend on `coralstack-cmd-ipc`
43// can still reach into `serde` / `schemars` / `serde_json` when they
44// want to.
45//
46// `serde` is re-exported so the derives emitted by `#[event]` and
47// `#[payload]` resolve against it without the user adding a direct
48// dependency. The `#[serde(crate = "...")]` / `#[schemars(crate = "...")]`
49// attributes the macros emit point at these re-exports.
50pub use coralstack_cmd_ipc_macros::{command, command_service, event, payload};
51pub use schemars;
52pub use serde;
53pub use serde_json;
54
55/// Curated re-exports for the common public API.
56///
57/// ```ignore
58/// use coralstack_cmd_ipc::prelude::*;
59/// ```
60pub mod prelude {
61 pub use crate::{
62 command, command_service, event, payload, BoxedDynCommand, ChannelError, Command,
63 CommandChannel, CommandDef, CommandError, CommandRegistry, CommandSchema, Config,
64 DynCommand, DynEvent, Event, InMemoryChannel,
65 };
66}