intercom-rs 1.1.1

A fully typed async wrapper for NATS with JetStream support
Documentation
//! # Intercom
//!
//! A fully typed async wrapper for NATS with JetStream support.
//!
//! ## Features
//!
//! - Fully typed publish/subscribe with turbofish syntax support
//! - Pluggable codec support (MessagePack default, JSON optional)
//! - JetStream support with builder pattern
//! - Push and pull consumers
//! - Interest-based consumers
//! - Work queues
//! - Stream trait for subscribers
//! - Sink trait for publishers
//!
//! ## Codec Selection
//!
//! The library supports multiple serialization codecs via cargo features:
//! - `msgpack` (default) - MessagePack binary serialization
//! - `json` - JSON text serialization
//!
//! When creating a client, specify the codec type:
//!
//! ```no_run
//! use intercom::{Client, MsgPackCodec, Result};
//!
//! # async fn example() -> Result<()> {
//! // Using MessagePack (default)
//! let client = Client::<MsgPackCodec>::connect("nats://localhost:4222").await?;
//! # Ok(())
//! # }
//! ```
//!
//! Or with JSON:
//!
//! ```ignore
//! use intercom::{Client, JsonCodec, Result};
//!
//! # async fn example() -> Result<()> {
//! // Using JSON (requires `json` feature)
//! let client = Client::<JsonCodec>::connect("nats://localhost:4222").await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Example
//!
//! ```no_run
//! use intercom::{Client, MsgPackCodec, Result};
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Debug, Serialize, Deserialize)]
//! struct MyMessage {
//!     content: String,
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//!     let client = Client::<MsgPackCodec>::connect("nats://localhost:4222").await?;
//!     
//!     // Type-safe publish
//!     client.publish::<MyMessage>("subject", &MyMessage { content: "hello".into() }).await?;
//!     
//!     // Create a typed subscriber with Stream trait
//!     let mut subscriber = client.subscribe::<MyMessage>("subject").await?;
//!     
//!     // Create a typed publisher with Sink trait
//!     let publisher = client.publisher::<MyMessage>("subject");
//!     
//!     Ok(())
//! }
//! ```
//!
//! ## JetStream Example
//!
//! ```no_run
//! use intercom::{Client, MsgPackCodec, Result};
//! use intercom::jetstream::stream::RetentionPolicy;
//! use serde::{Deserialize, Serialize};
//! use futures::StreamExt;
//!
//! #[derive(Debug, Serialize, Deserialize)]
//! struct Event {
//!     id: u64,
//!     data: String,
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//!     let client = Client::<MsgPackCodec>::connect("nats://localhost:4222").await?;
//!     let jetstream = client.jetstream();
//!     
//!     // Create a stream with builder pattern
//!     let stream = jetstream
//!         .stream_builder("events")
//!         .subjects(vec!["events.>".to_string()])
//!         .max_messages(1_000_000)
//!         .create()
//!         .await?;
//!     
//!     // Publish typed messages
//!     jetstream.publish::<Event>("events.user", &Event {
//!         id: 1,
//!         data: "user created".to_string(),
//!     }).await?;
//!     
//!     // Create a pull consumer with turbofish syntax
//!     let consumer = stream
//!         .pull_consumer_builder::<Event>("my-consumer")
//!         .durable()
//!         .create()
//!         .await?;
//!     
//!     // Fetch messages with Stream trait
//!     let mut messages = consumer.fetch(10).await?;
//!     while let Some(result) = messages.next().await {
//!         let msg = result?;
//!         println!("Got: {:?}", msg.payload);
//!         msg.ack().await?;
//!     }
//!     
//!     Ok(())
//! }
//! ```

pub mod client;
pub mod codec;
pub mod error;
pub mod jetstream;
pub mod publisher;
pub mod subscriber;

pub use client::Client;
pub use codec::{Codec, CodecType, Decode, Encode};
#[cfg(feature = "msgpack")]
pub use codec::MsgPackCodec;
#[cfg(feature = "json")]
pub use codec::JsonCodec;
#[cfg(any(feature = "msgpack", feature = "json"))]
pub use codec::DefaultCodec;
pub use error::{Error, Result};
pub use jetstream::consumer::{
    AckPolicy, DeliverPolicy, JetStreamMessage, PullBatch, PullConsumer, PullConsumerBuilder,
    PullMessages, PushConsumer, PushConsumerBuilder, PushMessages, ReplayPolicy,
};
pub use jetstream::context::{JetStreamContext, PublishAck, PublishAckFuture};
pub use jetstream::queue::{InterestQueue, InterestQueueBuilder, QueueMessage, StreamingWorkQueue, WorkQueue, WorkQueueBuilder, WorkQueueSink};
pub use jetstream::stream::{
    Compression, DiscardPolicy, RetentionPolicy, StorageType, Stream, StreamBuilder, StreamConfig,
    StreamInfo, StreamSource, StreamState,
};
pub use publisher::Publisher;
pub use subscriber::{Message, Subscriber};