Crate hsipc

Source
Expand description

§hsipc - High-performance inter-process communication framework

A declarative IPC framework built on top of ipmb, providing type-safe RPC and publish/subscribe patterns.

§Quick Start

§RPC Pattern

Define services using the #[rpc] macro:

use hsipc::{rpc, method, ProcessHub, Result};

#[rpc(server, client, namespace = "calculator")]
pub trait Calculator {
    #[method(name = "add")]
    async fn add(&self, a: i32, b: i32) -> Result<i32>;
}

#[tokio::main]
async fn main() -> Result<()> {
    let hub = ProcessHub::new("demo").await?;
     
    // Register service
    let service = CalculatorService::new(CalculatorImpl);
    hub.register_service(service).await?;
     
    // Use typed client
    let client = CalculatorClient::new(hub);
    let result = client.add(10, 5).await?;
    assert_eq!(result, 15);
     
    Ok(())
}

§Publish/Subscribe Pattern

Define events using the #[derive(Event)] macro:

use hsipc::{Event, ProcessHub, Result};
use serde::{Serialize, Deserialize};

#[derive(Event, Serialize, Deserialize, Debug, Clone)]
#[event(topic = "sensor/temperature")]
pub struct TemperatureEvent {
    pub value: f64,
    pub unit: String,
}

#[tokio::main]
async fn main() -> Result<()> {
    let hub = ProcessHub::new("demo").await?;
     
    // Publish event
    let event = TemperatureEvent {
        value: 25.3,
        unit: "Celsius".to_string(),
    };
    hub.publish_event(event).await?;
     
    Ok(())
}

§Available Macros

  • #[service] - CURRENT: Generate service wrappers and clients from impl blocks
  • #[derive(Event)] - PRIMARY: Implement Event trait for pub/sub
  • #[subscribe] - Mark subscriber functions (experimental)
  • #[service_impl] - TRAIT-BASED: Service implementation from trait (alternative approach)

§Design Trade-offs

#[service] approach: Simpler to use, single macro, but less type-safe interface definition

#[service_trait] + #[service_impl] approach: More type-safe, better interface separation, supports polymorphism and testing, but requires two macros

§Internal/Experimental Macros (not exported)

  • #[service_trait] - Generate clients from trait definitions (internal)
  • #[derive(Service)] - Service wrapper generation (experimental)

For detailed macro usage, see the macros module.

Re-exports§

pub use error::Error;
pub use error::Result;
pub use event::Event;
pub use event::Subscriber;
pub use event::Subscription;
pub use hub::ProcessHub;
pub use hub::SyncProcessHub;
pub use hub::Service;
pub use hub::ServiceRegistry;
pub use message::Message;
pub use message::Request;
pub use message::Response;
pub use subscription::PendingSubscriptionSink;
pub use subscription::RpcSubscription;
pub use subscription::SubscriptionSink;
pub use bincode;

Modules§

error
Error types for the hsipc library
event
Event trait and subscription system for publish/subscribe pattern
hub
ProcessHub - Main hub for inter-process communication
macros
Macro usage examples and documentation
message
Message types and serialization
subscription
RPC subscription system implementation
transport
Transport layer - simplified implementation with shared message bus
transport_ipmb
Real IPMB-based transport for cross-process communication

Traits§

Deserialize
A data structure that can be deserialized from any data format supported by Serde.
Serialize
A data structure that can be serialized into any data format supported by Serde.

Type Aliases§

SubscriptionResult

Attribute Macros§

async_trait
method
Method attribute macro for RPC methods (placeholder)
rpc
Main RPC macro - generates server and client code
subscribe
Attribute macro for subscription methods
subscription
Subscription attribute macro for RPC subscriptions (placeholder)

Derive Macros§

Deserialize
Event
Derive macro for creating events
Serialize