콘텐츠로 이동

zwire-serde (Bridge)

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

Optional serde serialization and deserialization bridge for zwire-protocol.

This crate keeps the core zwire Rust workspace 100% dependency-free while giving serde consumers:

  • to_wire(&value) / from_wire(&wire_value) converting any Serialize / Deserialize<'de> type to and from WireValue (including zero-copy borrowed &str/Cow<str> fields and integer/boolean map keys), preserving zwire’s lossless ±(2^53 - 1) integer string encoding for i64 and u64.
  • to_wire_json(&value) / from_wire_json(json) for direct canonical RFC-8259 JSON round-trips.
  • SerdeWire<T> implementing WireCodec (plus fallible SerdeWire::try_to_wire) so serde-derived structs and enums work directly with hydratable, sync_hydratable, and SyncBridge.
  • #[serde(with = "zwire_serde::wire_value")] and #[serde(with = "zwire_serde::state_patch")] helpers for embedding WireValue and StatePatch inside serde types.
use serde::{Deserialize, Serialize};
use zwire::prelude::*;
use zwire_serde::{SerdeWire, from_wire, to_wire};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
struct Profile {
name: String,
visits: u64,
}
let scope = Scope::new();
let profile = hydratable(
&scope,
"profile",
SerdeWire::new(Profile {
name: "Ada".into(),
visits: 1_u64 << 60,
}),
);
let wire = to_wire(&*scope.get(profile)).unwrap();
assert_eq!(from_wire::<Profile>(&wire).unwrap(), *scope.get(profile));