Blog Logo
TAGS

Effing-mad: An Algebraic Effect Library for Rust

Effing-mad is an experiment in how an effect system could fit into Rust. It brings algebraic effects and effect handlers to Rust, providing traits and macros for writing effectful code in more or less the same style as Rusts existing `async` functions. The library solves the function colouring problem and allows for effectful functions that can explicitly suspend their execution and pass control back to their callers. Data can be carried through both of these transitions and is strongly typed in the same way as one would expect in Rust. The effect handler performs the action and passes the result back into the effectful function, and execution continues. Calling functions upside down has fantastic advantages since effects are handled inside the caller instead of the callee. Different callers can use different handlers on the same effectful function, meaning an effectful function that performs I/O can be called from either a regular `fn` or an `async fn` and do the I/O in the natural way in both. The library is an API experimentation and fun and is unstable but has many cool features like procedural macros, unsafe, raw pointers, and Pin. Check out the examples directory for a demo of the librarys functionality.