Skip to main content

net/
lib.rs

1//! # Net
2//!
3//! High-performance, schema-agnostic, backend-agnostic event bus designed for
4//! AI runtime workloads.
5//!
6//! ## Primary Use Case
7//!
8//! Net is fundamentally designed to **ingest, relay, and replay
9//! AI-generated streaming output** at GPU-native speeds. Target workloads include:
10//!
11//! - **Token streams**: LLM output tokens as they're generated
12//! - **Multi-agent event flows**: Inter-agent communication in agentic systems
13//! - **Tool-use streams**: Function calls, API invocations, tool results
14//! - **Guardrail streams**: Safety checks, content filtering, policy enforcement
15//! - **Consensus streams**: Multi-model voting, ensemble decisions
16//! - **Structured-output parsing events**: JSON mode, schema validation
17//! - **Retry/fallback trees**: Failure handling, alternative paths
18//! - **Drift detection events**: Model behavior monitoring
19//! - **Session lifecycle streams**: Conversation state, context management
20//!
21//! ## Performance Targets
22//!
23//! - **≥ 10 million events/sec sustained ingestion**
24//! - **≥ 100 million events/sec microburst tolerance**
25//! - **< 1μs p99 ingestion latency**
26//!
27//! ## Quick Start
28//!
29//! ```rust,ignore
30//! use net::{EventBus, EventBusConfig, Event};
31//!
32//! #[tokio::main]
33//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
34//!     // Create event bus with default configuration
35//!     let bus = EventBus::new(EventBusConfig::default()).await?;
36//!
37//!     // Ingest events (non-blocking)
38//!     let event = Event::from_str(r#"{"token": "hello", "index": 0}"#)?;
39//!     bus.ingest(event)?;
40//!
41//!     // Poll events
42//!     let response = bus.poll(Default::default()).await?;
43//!     for event in response.events {
44//!         println!("{:?}", event.raw);
45//!     }
46//!
47//!     bus.shutdown().await?;
48//!     Ok(())
49//! }
50//! ```
51
52#![warn(missing_docs)]
53#![warn(clippy::all)]
54#![allow(clippy::module_inception)]
55#![recursion_limit = "256"]
56
57pub mod config;
58pub mod error;
59pub mod event;
60pub mod timestamp;
61
62pub mod adapter;
63pub mod bus;
64pub mod consumer;
65pub mod shard;
66
67pub use timestamp::TimestampGenerator;
68
69pub mod ffi;
70
71// Re-exports for convenience
72pub use bus::{EventBus, EventBusStats};
73#[cfg(feature = "jetstream")]
74pub use config::JetStreamAdapterConfig;
75#[cfg(feature = "redis")]
76pub use config::RedisAdapterConfig;
77pub use config::ScalingPolicy;
78pub use config::{
79    AdapterConfig, BackpressureMode, BatchConfig, ConfigError, EventBusConfig,
80    EventBusConfigBuilder,
81};
82pub use consumer::{ConsumeRequest, ConsumeResponse, Filter, Ordering};
83pub use error::{
84    AdapterError, AdapterResult, ConsumerError, ConsumerResult, IngestionError, IngestionResult,
85};
86pub use event::{Batch, Event, InternalEvent, RawEvent, StoredEvent};
87pub use shard::{ScalingDecision, ScalingError, ShardMetrics};