Announcing 'par' — session types in Rust for type-safe structured concurrency

73 points faiface

Hey there, Rustaceans!

I'm very happy to be finally able to present my take on how to do structured concurrency in Rust with a new implementation of session types!

I've been fascinated by the theory of session types and linear logic for quite a while and find it sad it's not really applied in the wild. The reason is obvious: there don't seem to be good enough implementations.

So I took my chance and I think I came up with something worth sharing.

Check it out!

I'm very curious to know what you think! Also, you're more than welcome to come and contribute, too.

Features

  • Specify full concurrent protocols — Sequencing, branching, recursion, higher-order patterns.
  • Type-checked protocol adherence — Expectations delivered, obligations fulfilled.
  • Deadlock freedom — Cyclic communication is statically ruled out.
  • Multiple concurrent participants.
  • Fits well with Rust's type system:
    • Use enums for making choices.
    • Use recursion on types for cyclic protocols.
  • Built on top of async/.await. Runtime agnostic.
  • Ergonomic design — eg. atm.choose(Operation::CheckBalance)
  • Standard patterns in modules:
    • Queue — Transmit an arbitrary number of items in order.
    • Server — Handle a dynamic number of clients concurrently.
  • No unsafe!
  • Accessible documentation as a learning tool.