Rusty Variation (RV) is a library for session-typed communication in Rust which offers strong compile-time correctness guarantees. Programs written using RV are guaranteed to respect a specified protocol, and are guaranteed to be free from deadlocks and races.
Rusty Variation
Types, sessions, and dualityThere are three basic types which we use to describe session protocols-or session types: Send, Recv, and End. We refer to values of these types as session endpoints or, when referring to both endpoints, sessions. Session endpoints wrap primitive channels-see section 2.6. Any type built using these primitive types is a valid session type:Session types are public, but their member functions are not. Therefore, users cannot construct their own misbehaving sessions. The continuation of a session must itself be a session. This is enforced by the Session constraint. In addition to this "kinding" of session types, the Session trait also requires any session type to implement duality and session generation: pub trait Session { type Dual: Session; fn new() -> (Self, Self::Dual); } Duality works as expected: Send is dual to Recv-and vice versa-and End is selfdual. The constraint Session enforces that the dual of a session type is a session type, and that S::Dual::Dual is equal to S (involutivity).The new function generates a new session-typed channel and returns two dual channel endpoints. Unlike the rest of the functions discussed in this section, new is not part of the public interface-see section 2.7.Using these types, we can define the types of servers which offer squaring or negation as follows, where i32 is the type of 32-bit integers:type SqrSrv = Recv>; type NegSrv = Recv>;The client types are obtained by duality.
Send, receive, close, and forkThe send and recv functions send and receive values in sessions. Sending is non-blocking, and never fails. Sending a value on a cancelled channel is equivalent to cancelling that value-see section 2.3. Receiving is blocking, and fails if the channel is cancelled.