#[derive(Debug, Clone, PartialEq)]
pub enum RtPayload {
Nothing,
Int(i64),
BigInt { negative: bool, magnitude: Vec<u8> },
Rational { num_negative: bool, num_magnitude: Vec<u8>, den_magnitude: Vec<u8> },
Decimal { negative: bool, magnitude: Vec<u8>, scale: u32 },
Money { negative: bool, magnitude: Vec<u8>, scale: u32, currency: String },
Uuid([u8; 16]),
Complex {
re_negative: bool,
re_num: Vec<u8>,
re_den: Vec<u8>,
im_negative: bool,
im_num: Vec<u8>,
im_den: Vec<u8>,
},
Modular { value: Vec<u8>, modulus: Vec<u8> },
Quantity {
num_negative: bool,
num_magnitude: Vec<u8>,
den_magnitude: Vec<u8>,
dim_num: Vec<i32>,
dim_den: Vec<i32>,
unit_symbol: String,
},
Float(f64),
Bool(bool),
Char(char),
Text(String),
List(Vec<RtPayload>),
Tuple(Vec<RtPayload>),
Set(Vec<RtPayload>),
Map(Vec<(RtPayload, RtPayload)>),
Struct {
type_name: String,
fields: Vec<(String, RtPayload)>,
},
Inductive {
type_name: String,
constructor: String,
args: Vec<RtPayload>,
},
Duration(i64),
Date(i32),
Moment(i64),
Span { months: i32, days: i32 },
Time(i64),
Word { width: u32, bits: u64 },
Chan(crate::channel::ChanId),
TaskHandle(crate::task::TaskId),
Peer(String),
}
#[cfg(test)]
mod tests {
use super::*;
fn assert_send<T: Send>() {}
#[test]
fn rtpayload_is_send() {
assert_send::<RtPayload>();
}
#[test]
fn rtpayload_roundtrips_structurally() {
let v = RtPayload::Struct {
type_name: "Point".into(),
fields: vec![
("x".into(), RtPayload::Int(1)),
(
"y".into(),
RtPayload::List(vec![RtPayload::Bool(true), RtPayload::Text("hi".into())]),
),
],
};
assert_eq!(v.clone(), v);
}
#[test]
fn rtpayload_nested_collections() {
let m = RtPayload::Map(vec![
(RtPayload::Text("a".into()), RtPayload::Int(1)),
(RtPayload::Text("b".into()), RtPayload::Set(vec![RtPayload::Char('x')])),
]);
match m {
RtPayload::Map(entries) => assert_eq!(entries.len(), 2),
_ => panic!("expected map"),
}
}
}