Crate wrpc_transport_derive
source ·Expand description
This crate exposes derive macros that enable Rust types to derive wrpc_transport::Encode
and wrpc_transport::Receive
traits.
§Example
ⓘ
use wrpc_transport_derive::{Encode, Receive};
#[derive(Trace, PartialEq, Eq, Encode, Receive, Default)]
struct TestStruct {
one: u32,
}
let mut buffer: Vec<u8> = Vec::new();
// Encode the TestStruct
TestStruct { one: 1 }
.encode(&mut buffer)
.await
.context("failed to perform encode")?;
// Attempt to receive the value
let (received, leftover): (TestStruct, _) =
Receive::receive_sync(Bytes::from(buffer), &mut empty())
.await
.context("failed to receive")?;
// At this point, we expect the received bytes to be exactly the same as what we started with
assert_eq!(received, TestStruct { one: 1 }, "received matches");
assert_eq!(leftover.remaining(), 0, "payload was completely consumed");
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
.
Modules§
- Dependencies of the macros container in the “inner” macro crate (
wrpc_transport_derive_macro
), hoisted to this level so they can be referenced from the inner macro, and are sure to be included
Traits§
- Re-export of
wrpc_transport::Encode
to make usage easier - Re-export of
wrpc_transport::Encode
to make usage easier
Derive Macros§
- Derive an [
wrpc_transport::Encode
] implementation - Derive an [
wrpc_transport::Receive
] implementation - Derive an [
wrpc_transport::Subscribe
] implementation