conduit-core 2.0.0

Binary IPC core: codec, router, ring buffer, handler trait.
Documentation

conduit-core

Crates.io docs.rs CI License

Binary IPC core for Tauri v2: codec, router, ring buffer, and ordered queue.

Part of the tauri-conduit workspace (v2.0.0).

Features

  • 11-byte frame codec with Encode/Decode traits for zero-parse binary serialization
  • Synchronous router for named command handlers (raw, JSON, and binary)
  • In-process ring buffer (RingBuffer) with lossy back-pressure for streaming
  • Ordered queue (Queue) with guaranteed delivery and backpressure
  • Channel abstraction (ChannelBuffer) unifying lossy and ordered channels

Key Types

Type Purpose
Router Named synchronous command registry (register, register_json, register_binary, call)
RingBuffer Thread-safe lossy circular buffer — oldest frames dropped on overflow
Queue Thread-safe ordered buffer — backpressure when full, no data loss
ChannelBuffer Enum wrapping RingBuffer (Lossy) or Queue (Reliable) with a unified push/drain API
ConduitHandler Trait for sync/async command handlers, implemented by #[command]-generated structs
HandlerResponse Enum: Sync(Result<Vec<u8>, Error>) or Async(Pin<Box<dyn Future>>)
HandlerContext Context passed to handlers: app handle + optional webview label
PushOutcome Enum: Accepted(usize) or TooLarge — opt-in via push_checked()
FrameHeader 11-byte binary frame header for all conduit messages
Encode / Decode Traits for fixed-layout binary serialization
Error Error types (UnknownCommand, DecodeFailed, Serialize, UnknownChannel, etc.)

Usage

use conduit_core::{Router, RingBuffer, Queue, ChannelBuffer, frame_pack, FrameHeader};

// Raw handler
let router = Router::new();
router.register("ping", |_| b"pong".to_vec());

let response = router.call("ping", vec![]).unwrap();
assert_eq!(response, b"pong");

// JSON handler
router.register_json("add", |args: (i32, i32)| args.0 + args.1);

// Binary handler (with Encode/Decode types)
// router.register_binary("process", |tick: MarketTick| tick);

Benchmarks

Includes a head-to-head comparison benchmark against JSON (serde):

cargo bench -- comparison   # JSON vs binary codec
cargo bench                 # all benchmarks

See the workspace README for full documentation and benchmark numbers.

License

Licensed under either of MIT or Apache-2.0 at your option.