콘텐츠로 이동

zwire-derive

이 콘텐츠는 아직 번역되지 않았습니다.

Enable the derive feature on zwire-protocol to derive WireCodec for concrete named-field structs. Every field must implement WireCodec. Generic structs, tuple structs and enums can implement the trait directly. The macro forwards field conversion to each field’s codec, including the lossless integer encoding. Unknown incoming object fields are ignored. All declared fields, including nullable fields, must be present.

use zwire_protocol::{WireCodec, WireValue};
#[derive(WireCodec)]
struct Account { sequence: u64, active: bool }
let account = Account { sequence: u64::MAX, active: true };
let decoded = Account::from_wire(&account.to_wire())?;

The macro expands through ::zwire_protocol by default. Facade users can select the re-export with #[wire(crate = zwire::protocol)], including when the protocol dependency has been renamed.