Skip to main content

Crate net

Crate net 

Source
Expand description

§Net

High-performance, schema-agnostic, backend-agnostic event bus designed for AI runtime workloads.

§Primary Use Case

Net is fundamentally designed to ingest, relay, and replay AI-generated streaming output at GPU-native speeds. Target workloads include:

  • Token streams: LLM output tokens as they’re generated
  • Multi-agent event flows: Inter-agent communication in agentic systems
  • Tool-use streams: Function calls, API invocations, tool results
  • Guardrail streams: Safety checks, content filtering, policy enforcement
  • Consensus streams: Multi-model voting, ensemble decisions
  • Structured-output parsing events: JSON mode, schema validation
  • Retry/fallback trees: Failure handling, alternative paths
  • Drift detection events: Model behavior monitoring
  • Session lifecycle streams: Conversation state, context management

§Performance Targets

  • ≥ 10 million events/sec sustained ingestion
  • ≥ 100 million events/sec microburst tolerance
  • < 1μs p99 ingestion latency

§Quick Start

use net::{EventBus, EventBusConfig, Event};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create event bus with default configuration
    let bus = EventBus::new(EventBusConfig::default()).await?;

    // Ingest events (non-blocking)
    let event = Event::from_str(r#"{"token": "hello", "index": 0}"#)?;
    bus.ingest(event)?;

    // Poll events
    let response = bus.poll(Default::default()).await?;
    for event in response.events {
        println!("{:?}", event.raw);
    }

    bus.shutdown().await?;
    Ok(())
}

Re-exports§

pub use timestamp::TimestampGenerator;
pub use bus::EventBus;
pub use bus::EventBusStats;
pub use config::ScalingPolicy;
pub use config::AdapterConfig;
pub use config::BackpressureMode;
pub use config::BatchConfig;
pub use config::ConfigError;
pub use config::EventBusConfig;
pub use config::EventBusConfigBuilder;
pub use consumer::ConsumeRequest;
pub use consumer::ConsumeResponse;
pub use consumer::Filter;
pub use consumer::Ordering;
pub use error::AdapterError;
pub use error::AdapterResult;
pub use error::ConsumerError;
pub use error::ConsumerResult;
pub use error::IngestionError;
pub use error::IngestionResult;
pub use event::Batch;
pub use event::Event;
pub use event::InternalEvent;
pub use event::RawEvent;
pub use event::StoredEvent;
pub use shard::ScalingDecision;
pub use shard::ScalingError;
pub use shard::ShardMetrics;

Modules§

adapter
Adapter trait and implementations for durable event storage.
bus
Main EventBus facade.
config
Configuration types for the Net event bus.
consumer
Consumer API for polling and filtering events.
error
Error types for the Net event bus.
event
Event types for the Net event bus.
ffi
C FFI bindings for cross-language integration.
shard
Shard management for parallel event ingestion.
timestamp
High-precision timestamp generation with zero syscall overhead.

Macros§

daemon_main
One-call macro for the common “single daemon per process” case. Expands to a tokio::main body that:
pred
Lightweight macro sugar over Predicate constructors. Mirrors the substrate plan’s macro-style examples in §6a; lowers to plain constructor calls so the AST stays the single source of truth.
require
require!(<spec>) — build a RequiredCapability from a string-literal spec. Panics at construction on malformed input (matches the substrate plan’s “validates shapes at parse time” contract for the macro family).
require_axis
require_axis!(<axis>) — build a RequiredCapability::AxisAny matching any tag in the named axis. Useful for “any device” / “any loaded model” intents where the application doesn’t need a specific tag, just something in the axis.
require_axis_value
require_axis_value!(<axis>, <key>) — build a RequiredCapability::AxisKey matching any tag with the given (axis, key) pair (presence OR value). Useful for “any version of this thing” intents — e.g. require_axis_value!("software", "model") matches software.model, software.model:llama-7b, or software.model=mistral-large interchangeably.