#[derive(DeriveMessage)]Expand description
Derive macro that generates a Pod-compatible wire struct from a domain struct.
Given a struct with bool, Option<numeric>, usize/isize, and
#[repr(u8)] enum fields, generates {Name}Wire plus From conversions
in both directions. Requires the derive feature.
ⓘ
#[derive(photon_ring::DeriveMessage)]
struct Order { price: f64, side: Side, filled: bool, tag: Option<u32> }
// Generates: OrderWire, From<Order> for OrderWire, From<OrderWire> for OrderDerive a Pod-compatible wire struct with From conversions.
Given a struct with fields that may include bool, Option<numeric>,
usize/isize, and #[repr(u8)] enums, generates:
{Name}Wire— a#[repr(C)] Clone + Copystruct with all fields converted to Pod-safe types, plusunsafe impl Pod.From<Name> for {Name}Wire— converts the domain struct to wire.From<{Name}Wire> for Name— converts the wire struct back.
§Field type mappings
| Source type | Wire type | To wire | From wire |
|---|---|---|---|
f32, f64, u8..u128, i8..i128 | same | passthrough | passthrough |
usize | u64 | as u64 | as usize |
isize | i64 | as i64 | as isize |
bool | u8 | if v { 1 } else { 0 } | v != 0 |
Option<T> (T numeric) | u64 | Some(x) => x as u64, None => 0 | 0 => None, v => Some(v as T) |
[T; N] (T: Pod) | same | passthrough | passthrough |
| Any other type | u8 | v as u8 | transmute(v) |
§Enum safety
Enum fields are converted via transmute from u8. The enum must
have #[repr(u8)] — the macro emits a compile-time size_of check to
enforce this.
§Example
ⓘ
#[repr(u8)]
#[derive(Clone, Copy)]
enum Side { Buy = 0, Sell = 1 }
#[derive(photon_ring::Message)]
struct Order {
price: f64,
qty: u32,
side: Side,
filled: bool,
tag: Option<u32>,
}
// Generates: OrderWire, From<Order> for OrderWire, From<OrderWire> for Order