From ffae9be241029e51eb0f4a82ec673c382ce60f83 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 24 Sep 2021 13:04:15 +0200 Subject: [PATCH] No more distinction between internal/external protocol variants --- syndicate/src/actor.rs | 5 +++-- syndicate/src/error.rs | 28 ++++++++++++++-------------- syndicate/src/relay.rs | 24 ++++++++++++------------ 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/syndicate/src/actor.rs b/syndicate/src/actor.rs index d0d3411..153eb77 100644 --- a/syndicate/src/actor.rs +++ b/syndicate/src/actor.rs @@ -13,6 +13,7 @@ use super::rewrite::CaveatError; use super::rewrite::CheckedCaveat; use super::schemas::sturdy; +use preserves::value::ArcValue; use preserves::value::Domain; use preserves::value::IOValue; use preserves::value::Map; @@ -53,7 +54,7 @@ use tracing::Instrument; /// `M`-values can be exchanged among objects, for distributed or /// polyglot systems a *lingua franca* has to be chosen. `AnyValue` is /// that language. -pub type AnyValue = super::schemas::internal_protocol::_Any; +pub type AnyValue = ArcValue>; /// The type of process-unique actor IDs. pub type ActorId = u64; @@ -236,7 +237,7 @@ pub type PendingEventQueue = Vec; /// values contained in an `Activation` are also sometimes useful. /// /// This is what other implementations call a "Turn", renamed here to -/// avoid conflicts with [`crate::schemas::internal_protocol::Turn`]. +/// avoid conflicts with [`crate::schemas::protocol::Turn`]. pub struct Activation<'activation> { /// A reference to the currently active [`Facet`] and the implementation-side state of its /// [`Actor`]. diff --git a/syndicate/src/error.rs b/syndicate/src/error.rs index 4c113c8..ecc7111 100644 --- a/syndicate/src/error.rs +++ b/syndicate/src/error.rs @@ -1,16 +1,16 @@ //! Actor errors. +use super::actor::AnyValue; use super::language; -use super::schemas::internal_protocol::_Any; - -#[doc(inline)] -pub use super::schemas::internal_protocol::Error; +use super::schemas::protocol as P; use preserves::value::NestedValue; use preserves::value::Value; use preserves_schema::Codec; use preserves_schema::ParseError; +pub type Error = P::Error; + impl std::error::Error for Error {} impl std::fmt::Display for Error { @@ -22,10 +22,10 @@ impl std::fmt::Display for Error { /// Construct an [`Error`] with the given `message` and `detail`. /// /// When no relevant detail exists, convention is to set `detail` to `false`. -pub fn error(message: &str, detail: Detail) -> Error where _Any: From { +pub fn error(message: &str, detail: Detail) -> Error where AnyValue: From { Error { message: message.to_owned(), - detail: _Any::from(detail), + detail: AnyValue::from(detail), } } @@ -35,15 +35,15 @@ pub fn error(message: &str, detail: Detail) -> Error where _Any: From) -> _Any { +pub fn encode_error(result: Result<(), Error>) -> AnyValue { match result { Ok(()) => { - let mut r = Value::record(_Any::symbol("Ok"), 1); - r.fields_vec_mut().push(Value::record(_Any::symbol("tuple"), 0).finish().wrap()); + let mut r = Value::record(AnyValue::symbol("Ok"), 1); + r.fields_vec_mut().push(Value::record(AnyValue::symbol("tuple"), 0).finish().wrap()); r.finish().wrap() } Err(e) => { - let mut r = Value::record(_Any::symbol("Err"), 1); + let mut r = Value::record(AnyValue::symbol("Err"), 1); r.fields_vec_mut().push(language().unparse(&e)); r.finish().wrap() } @@ -52,24 +52,24 @@ pub fn encode_error(result: Result<(), Error>) -> _Any { impl<'a> From<&'a str> for Error { fn from(v: &'a str) -> Self { - error(v, _Any::new(false)) + error(v, AnyValue::new(false)) } } impl From for Error { fn from(v: std::io::Error) -> Self { - error(&format!("{}", v), _Any::new(false)) + error(&format!("{}", v), AnyValue::new(false)) } } impl From for Error { fn from(v: ParseError) -> Self { - error(&format!("{}", v), _Any::new(false)) + error(&format!("{}", v), AnyValue::new(false)) } } impl From for Error { fn from(v: preserves::error::Error) -> Self { - error(&format!("{}", v), _Any::new(false)) + error(&format!("{}", v), AnyValue::new(false)) } } diff --git a/syndicate/src/relay.rs b/syndicate/src/relay.rs index 3352ff0..9173247 100644 --- a/syndicate/src/relay.rs +++ b/syndicate/src/relay.rs @@ -7,7 +7,7 @@ use crate::during; use crate::error::Error; use crate::error::error; use crate::schemas::gatekeeper; -use crate::schemas::internal_protocol as P; +use crate::schemas::protocol as P; use crate::schemas::sturdy; use futures::Sink; @@ -93,7 +93,7 @@ pub struct TunnelRelay inbound_assertions: Map>)>, outbound_assertions: Map>>, membranes: Membranes, - pending_outbound: Vec, + pending_outbound: Vec>, self_entity: Arc>, output: UnboundedSender>>, output_text: bool, @@ -251,7 +251,7 @@ impl TunnelRelay { result } - fn deserialize_one(&mut self, t: &mut Activation, bs: &[u8]) -> (Result, usize) { + fn deserialize_one(&mut self, t: &mut Activation, bs: &[u8]) -> (Result, ParseError>, usize) { let mut src = BytesBinarySource::new(&bs); let mut dec = ActivatedMembranes { turn: t, @@ -295,7 +295,7 @@ impl TunnelRelay { } } - fn handle_inbound_packet(&mut self, t: &mut Activation, p: P::Packet) -> ActorResult { + fn handle_inbound_packet(&mut self, t: &mut Activation, p: P::Packet) -> ActorResult { tracing::trace!(packet = ?p, "-->"); match p { P::Packet::Error(b) => { @@ -397,7 +397,7 @@ impl TunnelRelay { &mut self, _t: &mut Activation, remote_oid: sturdy::Oid, - event: &P::Event, + event: &P::Event, ) -> ActorResult { match event { P::Event::Assert(b) => { @@ -436,7 +436,7 @@ impl TunnelRelay { Ok(()) } - pub fn send_packet(&mut self, account: &Arc, cost: usize, p: P::Packet) -> ActorResult { + pub fn send_packet(&mut self, account: &Arc, cost: usize, p: P::Packet) -> ActorResult { let item = language().unparse(&p); tracing::trace!(packet = ?item, "<--"); @@ -452,7 +452,7 @@ impl TunnelRelay { Ok(()) } - pub fn send_event(&mut self, t: &mut Activation, remote_oid: sturdy::Oid, event: P::Event) -> ActorResult { + pub fn send_event(&mut self, t: &mut Activation, remote_oid: sturdy::Oid, event: P::Event) -> ActorResult { if self.pending_outbound.is_empty() { t.message_for_myself(&self.self_entity, ()); } @@ -517,7 +517,7 @@ impl Membranes { relay_ref: &TunnelRelayRef, src: &'src mut S, _read_annotations: bool, - ) -> io::Result { + ) -> io::Result> { let ws = match sturdy::WireRef::deserialize(&mut src.packed(NoEmbeddedDomainCodec))? { sturdy::WireRef::Mine{ oid: b } => { let oid = *b; @@ -549,21 +549,21 @@ impl Membranes { } } -impl<'a, 'activation, 'm> DomainDecode for ActivatedMembranes<'a, 'activation, 'm> { +impl<'a, 'activation, 'm> DomainDecode> for ActivatedMembranes<'a, 'activation, 'm> { fn decode_embedded<'de, 'src, S: BinarySource<'de>>( &mut self, src: &'src mut S, read_annotations: bool, - ) -> io::Result { + ) -> io::Result> { self.membranes.decode_embedded(self.turn, self.tr_ref, src, read_annotations) } } -impl DomainEncode for Membranes { +impl DomainEncode> for Membranes { fn encode_embedded( &mut self, w: &mut W, - d: &P::_Ptr, + d: &Arc, ) -> io::Result<()> { w.write(&mut NoEmbeddedDomainCodec, &language().unparse(&match self.exported.ref_map.get(d) { Some(ws) => sturdy::WireRef::Mine {