I’m pretty much done with my Rust protocol impl. The last thing that I wanted to try was to see how it would look like when I allow for messages to be handled out of band.
Right now, my code consuming the protocol library looks like this:
This is pretty simple, but note that the function definition forces us to return a value immediately, and that we don’t have a way to handle a command asynchronously.
What I wanted to do is to change things around so I could do that. I decided to implemented the command:
remind 15 Nap
Which should help me remember to nap. In order to handle this scenario, I need to provide a way to do async work and to keep sending messages to the client. Here was the first change I made:
Instead of returning a value from the function, we are going to give it the sender (which will render the value to the client) and can return an error if the command is invalid in some form.
That said, it means that the echo implementation is a bit more complex.
There is… a lot of ceremony here, even for something so small. Let’s see what happens when we do something bigger, shall we? Here is the implementation of the reminder handler:
Admittedly, a lot of that is error handling, but there is a lot of code here to do something that simple. Compare that to something like C#, where the same thing could be written as:
I’m not sure that the amount of complexity that is brought about by the tokio model, even with the async/await macros is worth it at this point. I believe that it needs at least a few more iterations before it is going to be usable for the general public.
There is way too much ceremony and work to be done, and a single miss and you are faced with a very pissed off compiler.