From 0c4496ae0767e3ceca470508ba7f818f449ad08a Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Sun, 10 Nov 2024 12:11:58 -0800 Subject: [PATCH] rename 'encoded_message' to 'decoded_message' --- Cargo.toml | 2 +- src/kv.rs | 4 +--- src/lib.rs | 26 ++++++++++++++------------ src/protocol.rs | 7 ++++--- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f4fc5b1..cf159a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "nebkor-maelstrom" edition = "2021" -version = "1.0.0" +version = "1.0.1" license-file = "LICENSE.md" readme = "README.md" description = "An easy-to-use and synchronous client for creating Maelstrom distributed clients." diff --git a/src/kv.rs b/src/kv.rs index ad67ede..0cce779 100644 --- a/src/kv.rs +++ b/src/kv.rs @@ -1,6 +1,4 @@ -use crate::Value; - -use crate::{check_err, mk_payload, Body, RpcResult, Runner}; +use crate::{check_err, mk_payload, Body, RpcResult, Runner, Value}; /// A convenient way to do RPC with Maelstrom's KV services. #[derive(Debug, Default, Clone)] diff --git a/src/lib.rs b/src/lib.rs index 1e95a88..9052b51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,9 +49,9 @@ impl Runner { } } - /// Start processing messages from stdin and sending them to your node. The `on_init` argument - /// is an optional callback that will be called with `&self` after the `init` message from - /// Maelstrom has been processed. + /// Start processing messages from stdin and sending them to your node. The + /// `on_init` argument is an optional callback that will be called with + /// `&self` after the `init` message from Maelstrom has been processed. /// /// # Examples /// @@ -88,9 +88,10 @@ impl Runner { self.process_input(on_init); } - /// Get a Sender that will send Messages to the node as input. Useful for triggering periodic - /// behavior from a separate thread, or for sending a Message to the node from `on_init`. See - /// the `broadcast` example for a use of it. + /// Get a Sender that will send Messages to the node as input. Useful for + /// triggering periodic behavior from a separate thread, or for sending + /// a Message to the node from `on_init`. See the `broadcast` example + /// for a use of it. pub fn get_backdoor(&self) -> Sender { self.backdoor.get().unwrap().clone() } @@ -123,7 +124,8 @@ impl Runner { self.outbound_tx.get().unwrap().send(msg).unwrap(); } - /// Returns a Receiver that will receive the reply from the request. + /// Returns a Receiver that will receive the reply from the + /// request. pub fn rpc(&self, dest: &str, body: Body) -> RpcPromise { let msg = self.mk_msg(dest, body); let (tx, rx) = channel(); @@ -164,8 +166,8 @@ impl Runner { fn process_input(&self, on_init: Option) { // for sending Messages to the node's inputs - let (encoded_input_tx, encoded_input_rx) = channel(); - let _ = self.backdoor.get_or_init(|| encoded_input_tx.clone()); + let (decoded_input_tx, decoded_input_rx) = channel(); + let _ = self.backdoor.get_or_init(|| decoded_input_tx.clone()); // decouple stdin from processing let proms = self.promises.clone(); @@ -179,13 +181,13 @@ impl Runner { promise.send(msg).unwrap(); } else { // just let the node's `handle()` method handle it - encoded_input_tx.send(msg).unwrap(); + decoded_input_tx.send(msg).unwrap(); } } }); // first Message is always `init`: - let msg = encoded_input_rx.recv().unwrap(); + let msg = decoded_input_rx.recv().unwrap(); { self.init(&msg); let body = Body::from_type("init_ok"); @@ -197,7 +199,7 @@ impl Runner { // every other message is for the node's handle() method let mut node = self.node.lock().unwrap(); - for msg in encoded_input_rx { + for msg in decoded_input_rx { node.handle(self, msg); } } diff --git a/src/protocol.rs b/src/protocol.rs index 4561ec7..56d64a5 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -52,9 +52,10 @@ impl Message { m } - /// The Maelstrom type of a Body (and hence a Message) is just a string. This is for the sake of - /// ease of use for doing the Gossip Glomers challenges; this crate is not meant to be a real - /// network client framework. + /// The Maelstrom type of a Body (and hence a Message) is just a string. + /// This is for the sake of ease of use for doing the Gossip Glomers + /// challenges; this crate is not meant to be a real network client + /// framework. pub fn typ(&self) -> &str { self.body.typ.as_str() }