1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! This library provides a simple and efficient way to transfer objects between
//! different parts of an application or between different applications through
//! message brokers like NATS.
//! It supports serialization and/or deserialization of various data formats,
//! making it easy to send and/or receive complex data structures.
//!
//! # Pluggable Encoder/Decoder Architecture
//!
//! A key feature of this library is its **"any-format"** design: you can use any
//! serialization format by implementing the [`encoders::Encoder`] and [`encoders::Decoder`] traits.
//! The library doesn't restrict you to built-in formats—JSON, MessagePack, Protocol Buffers,
//! CBOR, or custom formats all work seamlessly.
//!
//! ## Quick Example
//!
//! ```rust,no_run
//! use std::sync::Arc;
//! use serde::{Serialize, Deserialize};
//! use object_transfer::{
//! encoders::{JSONEncoder, JSONDecoder},
//! Pub, Sub, SubOpt,
//! traits::PubTrait,
//! };
//!
//! #[derive(Serialize, Deserialize, Clone, Debug)]
//! struct Event {
//! id: u32,
//! message: String,
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = async_nats::connect("demo.nats.io").await?;
//! let js = Arc::new(async_nats::jetstream::new(client));
//!
//! // Create a publisher with JSON encoder
//! let publisher: Pub<Event, _> = Pub::new(
//! js.clone(),
//! "events",
//! Arc::new(JSONEncoder::new()),
//! );
//!
//! let event = Event { id: 1, message: "Hello".to_string() };
//! publisher.publish(&event).await?;
//! Ok(())
//! }
//! ```
//!
//! ## Implementing Custom Formats
//!
//! Implement [`encoders::Encoder`] and [`encoders::Decoder`] for your format:
//!
//! ```rust
//! use bytes::Bytes;
//! use serde::Serialize;
//! use object_transfer::encoders::Encoder;
//!
//! struct MyFormat;
//! #[derive(serde::Serialize)]
//! struct MyData { id: u32 }
//!
//! impl Encoder for MyFormat {
//! type Item = MyData;
//! type Error = std::fmt::Error;
//!
//! fn encode(&self, item: &Self::Item) -> Result<Bytes, Self::Error> {
//! Ok(Bytes::from(format!("id:{}", item.id)))
//! }
//! }
//! ```
//!
//! Then pass your encoder/decoder to [`Pub::new()`] or [`Sub::new()`].
//!
//! # CI/CD Status
//!
//! | Service | Status |
//! |---------|--------|
//! | Crates.io | [![Crates.io Version Img]][Crates.io] |
//! | Code Test | [![Test Rust Code Img]][Test Rust Code] |
//!
//! [Test Rust Code Img]: https://github.com/hiroaki-yamamoto/object-transfer/actions/workflows/test_rust.yml/badge.svg
//! [Test Rust Code]: https://github.com/hiroaki-yamamoto/object-transfer/actions/workflows/test_rust.yml
//! [Crates.io Version Img]: https://img.shields.io/crates/v/object_transfer.svg
//! [Crates.io]: https://crates.io/crates/object_transfer
pub use AckNoop;
pub use SubOpt;
pub use Pub;
pub use Sub;
pub use ;
pub use UnSubNoop;