wrpc_transport_derive/lib.rs
1//! This crate exposes derive macros that enable Rust types to derive [`wrpc_transport::Encode`] and [`wrpc_transport::Receive`] traits.
2//!
3//! # Example
4//!
5//! ```rust,ignore
6//! use wrpc_transport_derive::{Encode, Receive};
7//!
8//! #[derive(Trace, PartialEq, Eq, Encode, Receive, Default)]
9//! struct TestStruct {
10//! one: u32,
11//! }
12//!
13//! let mut buffer: Vec<u8> = Vec::new();
14//! // Encode the TestStruct
15//! TestStruct { one: 1 }
16//! .encode(&mut buffer)
17//! .await
18//! .context("failed to perform encode")?;
19//!
20//! // Attempt to receive the value
21//! let (received, leftover): (TestStruct, _) =
22//! Receive::receive_sync(Bytes::from(buffer), &mut empty())
23//! .await
24//! .context("failed to receive")?;
25//!
26//! // At this point, we expect the received bytes to be exactly the same as what we started with
27//! assert_eq!(received, TestStruct { one: 1 }, "received matches");
28//! assert_eq!(leftover.remaining(), 0, "payload was completely consumed");
29//! ```
30//!
31//! NOTE: This macro crate uses `tracing`, so if you'd like to see the input & output tokens, prepend your command (ex. `cargo build`) with `RUST_LOG=trace`.
32//!
33
34/// Dependencies of the macros container in the "inner" macro crate (`wrpc_transport_derive_macro`),
35/// hoisted to this level so they can be referenced from the inner macro, and are sure to be included
36pub mod deps {
37 pub use anyhow;
38 pub use async_trait;
39 pub use bytes;
40 pub use futures;
41 pub use wrpc_transport;
42}
43
44pub use wrpc_transport_derive_macro::{Encode, Receive, Subscribe};
45
46/// Re-export of [`wrpc_transport::Encode`] to make usage easier
47pub use wrpc_transport::{Encode, Receive};