#session #types

nightly nemo

Session types for asynchronous networking

5 unstable releases

Uses old Rust 2015

0.2.1 Oct 26, 2015
0.2.0 Oct 24, 2015
0.1.1 Oct 23, 2015
0.1.0 Oct 23, 2015
0.0.1 Oct 21, 2015

#22 in #session

33 downloads per month

MIT license

379 lines

nemo Build status Crates.io


Nemo is a Rust language session types library which focuses on asynchronous networking interfaces. Session types are a way of embedding a protocol into the typesystem, such that the implementation of it must be correct, or the code simply cannot compile. The standard of "correct" is that no client will disagree on the expectations or state of another. Session types can be used to enforce that only certain messages can be sent in particular orders over the network. Session types can embed much more complicated logic to handle protocols which involve nested or recursive state changes.

How does nemo work?

The session_types crate is where nemo draws most of its inspiration. In order to support asynchronous channels and generic IO backends, it is designed differently so that you may defer a channel's handler to a future time -- perhaps when another event takes place on the network, or when it is convenient to resume work. If you never defer, there is no runtime cost, and when you do, the runtime cost is only one layer of indirection, sans code inlining. This change not only allows for async IO primitives, but also removes restrictions and requirements of end-user code.

Nemo provides an IO trait for implementing backends. As an example, nemo provides nemo::channels::Blocking which uses a backing bi-directional MPSC abstraction for safe communication between threads.

Advantages to building network protocols with nemo

  • Message tagging can be reduced or eliminated in some situations
  • Complicated protocols can be described and implemented in a way that does not cause safety issues or race conditions/unexpected behavior
  • IO backends can be swapped at any time, or wrapped for simulation purposes

No runtime deps