Update to Preserves 0.7

This commit is contained in:
Tony Garnock-Jones 2020-06-15 16:15:52 +02:00
parent 14b7aad9c6
commit 648fa58d3d
8 changed files with 39 additions and 27 deletions

4
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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<dyn std::error::Error>> {
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));

View File

@ -87,13 +87,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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()));
}
}
_ =>

View File

@ -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<dyn std::error::Error>> {
let config = Config::from_args();
@ -26,11 +34,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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?;

View File

@ -13,16 +13,16 @@ use tokio::time::interval;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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));

View File

@ -13,7 +13,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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());

View File

@ -335,7 +335,7 @@ where FCont: FnMut(&mut Continuation, &CachedAssertion) -> (),
fn class_of(v: &Assertion) -> Option<Guard> {
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)
}
}