I’ve been working through the challenges in Rust, and been writing my own Maelstrom crate as I went along. Now that I’ve got RPC and a KV proxy working, I think it’s ready for showing its face in public:
Features:
- no async, only three external deps (all of which are Serde-related), builds in less than a second
- almost no boilerplate (the complete echo client is in the readme, it’s like fifteen lines)
- includes a KV proxy with
read
,write
, andcas
methods that return aResult<Option<serde_json::Value>, crate::ErrorCode>
I wanted it to be as simple as possible to use, and I think it nails it.
Echo:
use nebkor_maelstrom::{Body, Message, Node, Runner};
struct Echo;
impl Node for Echo {
fn handle(&mut self, runner: &Runner, msg: Message) {
let typ = &msg.body.typ;
if typ.as_str() == "echo" {
let body = Body::from_type("echo_ok").with_payload(msg.body.payload.clone());
runner.reply(&msg, body);
}
}
}
fn main() {
let node = Echo;
let runner = Runner::new(node);
runner.run(None);
}