rogue_runtime/lib.rs
1//! runtime crate
2//!
3//! Provides the core infrastructure for asynchronous RPC, including:
4//! - `Runtime`: manages message dispatch and executor registration.
5//! - `CONTEXT`: task-local RPC context for client and server execution.
6//! - Traits: `MessageHandler` and `TypeInfo` for defining handlers.
7//! - Message definitions and serialization utilities.
8mod inventory_item;
9mod message;
10mod object_ref;
11mod runtime;
12mod traits;
13
14use tokio::sync::mpsc;
15use ulid::Ulid;
16
17pub mod api;
18pub mod prelude;
19
20pub use async_trait::async_trait;
21pub use inventory_item::*;
22pub use object_ref::*;
23pub use rogue_macros::rpc;
24pub use runtime::*;
25pub use traits::*;
26
27// re-export for macro use
28pub use inventory;
29pub use serde;
30pub use sha2;
31pub use tracing;
32
33pub type RuntimeId = String;
34pub type TypeId = [u8; 32];
35pub type InstanceId = Ulid;
36
37pub(crate) type MessageId = Ulid;
38
39#[derive(Clone)]
40/// Task-local execution context for RPC calls.
41///
42/// Holds the current target runtime ID, a shared reference to the `Runtime`,
43/// and a channel to report internal errors during RPC processing.
44pub struct RuntimeContext {
45 /// The identifier of the runtime that RPC calls are targeting.
46 pub target_id: RuntimeId,
47 /// Shared reference to the runtime instance handling messages.
48 pub runtime: Runtime,
49 /// Sender for internal error reporting within the execution scope.
50 pub error_tx: mpsc::Sender<anyhow::Error>,
51}
52
53tokio::task_local! {
54 pub static CONTEXT: RuntimeContext;
55}