1 个不稳定版本
0.1.0 | 2024 年 3 月 27 日 |
---|
1190 在 WebAssembly
在 2 个 Crate 中使用(通过 wrpc-transport-derive)
33KB
541 代码行
此 crate 包含 derive 宏,允许 Rust 类型派生 wrpc_transport::Encode
和 wrpc_transport::Receive
特性。
此 crate 旨在通过 wrpc-transport-derive
使用,它是包含此(内部)宏 crate 所需依赖项的伞形 crate。
示例
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");
注意:此宏 crate 使用 tracing
,因此如果您想查看输入和输出标记,请在命令(例如 cargo build
)之前添加 RUST_LOG=trace
。
依赖项
~7MB
~115K SLoC