From 648fa58d3d1e4b224a98e16080054a26da388d91 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 15 Jun 2020 16:15:52 +0200 Subject: [PATCH] Update to Preserves 0.7 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- examples/consumer.rs | 15 +++++++++++---- examples/pingpong.rs | 14 +++++++------- examples/producer.rs | 17 +++++++++++------ examples/state-consumer.rs | 8 ++++---- examples/state-producer.rs | 2 +- src/skeleton.rs | 4 ++-- 8 files changed, 39 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31de953..a967aec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -727,9 +727,9 @@ checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" [[package]] name = "preserves" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fab2d8978c0916b67126c6fcd927a37ecbaa6469dd18ec25dac346d61eca7bd" +checksum = "925929f873a9dff97fbe4e369e7ecfd3c950e315cbd4630a7856507134d0d810" dependencies = [ "lazy_static", "num", diff --git a/Cargo.toml b/Cargo.toml index 6ef844f..e011ef4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ lto = true name = "syndicate" [dependencies] -preserves = "0.6.0" +preserves = "0.7.0" serde = { version = "1.0", features = ["derive", "rc"] } serde_bytes = "0.11" diff --git a/examples/consumer.rs b/examples/consumer.rs index 9adaeff..67be844 100644 --- a/examples/consumer.rs +++ b/examples/consumer.rs @@ -11,18 +11,25 @@ use futures::select; use core::time::Duration; use tokio::time::interval; +#[inline] +fn says(who: V, what: V) -> V { + let mut r = Value::simple_record("Says", 2); + r.fields_vec_mut().push(who); + r.fields_vec_mut().push(what); + r.finish().wrap() +} + #[tokio::main] async fn main() -> Result<(), Box> { - let discard: V = Value::simple_record("discard", vec![]).wrap(); - let capture: V = Value::simple_record("capture", vec![discard]).wrap(); + let discard: V = Value::simple_record0("discard").wrap(); + let capture: V = Value::simple_record1("capture", discard).wrap(); let mut frames = Framed::new(TcpStream::connect("127.0.0.1:8001").await?, ClientCodec::new()); frames.send(C2S::Connect(Value::from("chat").wrap())).await?; frames.send( C2S::Turn(vec![Action::Assert( Value::from(0).wrap(), - Value::simple_record("observe", vec![ - Value::simple_record("Says", vec![capture.clone(), capture]).wrap()]).wrap())])) + Value::simple_record1("observe", says(capture.clone(), capture)).wrap())])) .await?; let mut stats_timer = interval(Duration::from_secs(1)); diff --git a/examples/pingpong.rs b/examples/pingpong.rs index 37109b1..76ac8ef 100644 --- a/examples/pingpong.rs +++ b/examples/pingpong.rs @@ -87,13 +87,13 @@ async fn main() -> Result<(), Box> { let mut frames = Framed::new(TcpStream::connect("127.0.0.1:8001").await?, ClientCodec::new()); frames.send(C2S::Connect(Value::from(config.dataspace).wrap())).await?; - let discard = Value::simple_record("discard", vec![]).wrap(); - let capture = Value::simple_record("capture", vec![discard]).wrap(); + let discard = Value::simple_record0("discard").wrap(); + let capture = Value::simple_record1("capture", discard).wrap(); frames.send( C2S::Turn(vec![Action::Assert( Value::from(0).wrap(), - Value::simple_record("observe", vec![ - Value::simple_record(recv_label, vec![capture]).wrap()]).wrap())])) + Value::simple_record1("observe", + Value::simple_record1(recv_label, capture).wrap()).wrap())])) .await?; let mut stats_timer = interval(Duration::from_secs(1)); @@ -107,7 +107,7 @@ async fn main() -> Result<(), Box> { current_stamp = Value::from(now()?).wrap(); for _ in 0..c.action_count { actions.push(Action::Message( - Value::simple_record(send_label, vec![current_stamp.clone()]).wrap())); + Value::simple_record1(send_label, current_stamp.clone()).wrap())); } frames.send(C2S::Turn(actions)).await?; } @@ -137,7 +137,7 @@ async fn main() -> Result<(), Box> { Event::Msg(_, captures) => { if should_echo || (report_latency_every == 0) { actions.push(Action::Message( - Value::simple_record(send_label, vec![captures[0].clone()]).wrap())); + Value::simple_record1(send_label, captures[0].clone()).wrap())); } else { if !have_sample { let rtt_ns = now()? - captures[0].value().to_u64()?; @@ -154,7 +154,7 @@ async fn main() -> Result<(), Box> { current_stamp = Value::from(now()?).wrap(); } actions.push(Action::Message( - Value::simple_record(send_label, vec![current_stamp.clone()]).wrap())); + Value::simple_record1(send_label, current_stamp.clone()).wrap())); } } _ => diff --git a/examples/producer.rs b/examples/producer.rs index 82bb2fa..8a3e64f 100644 --- a/examples/producer.rs +++ b/examples/producer.rs @@ -5,7 +5,7 @@ use tokio::net::TcpStream; use tokio_util::codec::Framed; use syndicate::packets::{ClientCodec, C2S, S2C, Action}; -use syndicate::value::Value; +use syndicate::value::{Value, IOValue}; #[derive(Clone, Debug, StructOpt)] pub struct Config { @@ -13,6 +13,14 @@ pub struct Config { action_count: u32, } +#[inline] +fn says(who: IOValue, what: IOValue) -> IOValue { + let mut r = Value::simple_record("Says", 2); + r.fields_vec_mut().push(who); + r.fields_vec_mut().push(what); + r.finish().wrap() +} + #[tokio::main] async fn main() -> Result<(), Box> { let config = Config::from_args(); @@ -26,11 +34,8 @@ async fn main() -> Result<(), Box> { let mut actions = vec![]; for _ in 0..config.action_count { - actions.push(Action::Message( - Value::simple_record("Says", vec![ - Value::from("producer").wrap(), - Value::from(counter).wrap(), - ]).wrap())); + actions.push(Action::Message(says(Value::from("producer").wrap(), + Value::from(counter).wrap()))); } frames.send(C2S::Turn(actions)).await?; diff --git a/examples/state-consumer.rs b/examples/state-consumer.rs index 793b198..5a5d766 100644 --- a/examples/state-consumer.rs +++ b/examples/state-consumer.rs @@ -13,16 +13,16 @@ use tokio::time::interval; #[tokio::main] async fn main() -> Result<(), Box> { - let discard: V = Value::simple_record("discard", vec![]).wrap(); - let capture: V = Value::simple_record("capture", vec![discard]).wrap(); + let discard: V = Value::simple_record0("discard").wrap(); + let capture: V = Value::simple_record1("capture", discard).wrap(); let mut frames = Framed::new(TcpStream::connect("127.0.0.1:8001").await?, ClientCodec::new()); frames.send(C2S::Connect(Value::from("chat").wrap())).await?; frames.send( C2S::Turn(vec![Action::Assert( Value::from(0).wrap(), - Value::simple_record("observe", vec![ - Value::simple_record("Present", vec![capture]).wrap()]).wrap())])) + Value::simple_record1("observe", + Value::simple_record1("Present", capture).wrap()).wrap())])) .await?; let mut stats_timer = interval(Duration::from_secs(1)); diff --git a/examples/state-producer.rs b/examples/state-producer.rs index c6b9c4f..c226251 100644 --- a/examples/state-producer.rs +++ b/examples/state-producer.rs @@ -13,7 +13,7 @@ async fn main() -> Result<(), Box> { let present_action = Action::Assert( Value::from(0).wrap(), - Value::simple_record("Present", vec![Value::from(std::process::id()).wrap()]).wrap()); + Value::simple_record1("Present", Value::from(std::process::id()).wrap()).wrap()); let absent_action = Action::Clear( Value::from(0).wrap()); diff --git a/src/skeleton.rs b/src/skeleton.rs index 08ff120..d9b4610 100644 --- a/src/skeleton.rs +++ b/src/skeleton.rs @@ -335,7 +335,7 @@ where FCont: FnMut(&mut Continuation, &CachedAssertion) -> (), fn class_of(v: &Assertion) -> Option { match v.value() { Value::Sequence(ref vs) => Some(Guard::Seq(vs.len())), - Value::Record((ref l, ref fs)) => Some(Guard::Rec(l.clone(), fs.len())), + Value::Record(ref r) => Some(Guard::Rec(r.label().clone(), r.arity())), _ => None, } } @@ -355,7 +355,7 @@ fn project_paths<'a>(v: &'a Assertion, ps: &Paths) -> Captures { fn step(v: &Assertion, i: usize) -> &Assertion { match v.value() { Value::Sequence(ref vs) => &vs[i], - Value::Record((_, ref fs)) => &fs[i], + Value::Record(ref r) => &r.fields()[i], _ => panic!("step: non-sequence, non-record {:?}", v) } }