rogue-runtime 0.1.0

Async RPC Runtime
Documentation
//! runtime crate
//!
//! Provides the core infrastructure for asynchronous RPC, including:
//! - `Runtime`: manages message dispatch and executor registration.
//! - `CONTEXT`: task-local RPC context for client and server execution.
//! - Traits: `MessageHandler` and `TypeInfo` for defining handlers.
//! - Message definitions and serialization utilities.
mod inventory_item;
mod message;
mod object_ref;
mod runtime;
mod traits;

use tokio::sync::mpsc;
use ulid::Ulid;

pub mod api;
pub mod prelude;

pub use async_trait::async_trait;
pub use inventory_item::*;
pub use object_ref::*;
pub use rogue_macros::rpc;
pub use runtime::*;
pub use traits::*;

// re-export for macro use
pub use inventory;
pub use serde;
pub use sha2;
pub use tracing;

pub type RuntimeId = String;
pub type TypeId = [u8; 32];
pub type InstanceId = Ulid;

pub(crate) type MessageId = Ulid;

#[derive(Clone)]
/// Task-local execution context for RPC calls.
///
/// Holds the current target runtime ID, a shared reference to the `Runtime`,
/// and a channel to report internal errors during RPC processing.
pub struct RuntimeContext {
    /// The identifier of the runtime that RPC calls are targeting.
    pub target_id: RuntimeId,
    /// Shared reference to the runtime instance handling messages.
    pub runtime: Runtime,
    /// Sender for internal error reporting within the execution scope.
    pub error_tx: mpsc::Sender<anyhow::Error>,
}

tokio::task_local! {
    pub static CONTEXT: RuntimeContext;
}