add doc comment for mk_payload
This commit is contained in:
parent
c7f3c21fd0
commit
6195807355
2 changed files with 3 additions and 36 deletions
|
@ -1,10 +1,10 @@
|
|||
[package]
|
||||
name = "nebkor-maelstrom"
|
||||
edition = "2024"
|
||||
version = "1.1.0"
|
||||
version = "1.1.1"
|
||||
license-file = "LICENSE.md"
|
||||
readme = "README.md"
|
||||
description = "An easy-to-use and synchronous client for creating Maelstrom distributed clients."
|
||||
description = "An easy-to-use and synchronous framework for creating Maelstrom distributed clients."
|
||||
repository = "https://git.kittencollective.com/nebkor/nebkor-maelstrom"
|
||||
keywords = ["maelstrom", "glomers", "gossip", "distributed"]
|
||||
|
||||
|
|
35
src/lib.rs
35
src/lib.rs
|
@ -1,5 +1,5 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
collections::HashMap,
|
||||
io::{BufRead, Write},
|
||||
sync::{
|
||||
Arc, Mutex, OnceLock,
|
||||
|
@ -20,7 +20,6 @@ pub type NodeyNodeFace = Arc<Mutex<dyn Node>>;
|
|||
pub type OnInit = Box<dyn Fn(&Runner)>;
|
||||
pub type RpcFuture = Receiver<Message>;
|
||||
pub type RpcResult = std::result::Result<Option<Value>, ErrorCode>;
|
||||
pub type Topology = BTreeMap<String, Vec<String>>;
|
||||
|
||||
pub trait Node {
|
||||
fn handle(&mut self, runner: &Runner, msg: Message);
|
||||
|
@ -233,35 +232,3 @@ pub fn mk_payload(payload: &[(&str, Value)]) -> Payload {
|
|||
.map(|p| (p.0.to_string(), p.1.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Convenience function for turning a `topology` message into a map of node ->
|
||||
/// neighbors (String -> Vec<String>).
|
||||
pub fn parse_toplogy(msg: &Message) -> Option<Topology> {
|
||||
if msg.typ() != "topology" {
|
||||
return None;
|
||||
}
|
||||
let topology = msg
|
||||
.body
|
||||
.payload
|
||||
.get("topology")
|
||||
.unwrap()
|
||||
.as_object()
|
||||
.cloned()
|
||||
.unwrap();
|
||||
Some(
|
||||
topology
|
||||
.into_iter()
|
||||
.map(|(node, neighbors)| {
|
||||
(
|
||||
node,
|
||||
neighbors
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|neighbor| neighbor.as_str().unwrap().to_string())
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue