1 个不稳定版本

0.1.0 2024年3月27日

#805WebAssembly


wasmcloud-provider-wit-bi… 中使用

Apache-2.0

8KB
63

此crate公开了derive宏,使Rust类型能够推导wrpc_transport::Encodewrpc_transport::Receive特性。

示例

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

依赖关系

~24–36MB
~671K SLoC