RRust, a reversible Rust DSL

Related tags

Database RRust

RRust, reversible DSL for Rust

RRust is a reversible subset of Rust inside of Rust, this means you can use it to write a algorithm and then it can run forwards as usually, but it can also run in the reverse direction undoing everything it just did.


use rrust::{rfn, rif};

rfn!(Fib, (x1: &mut i32, x2: &mut i32, n: &mut i32), {
        *n == 0,
            *x1 += 1;
            *x2 += 1;
            *n -= 1;
            Fib::forward(x1, x2, n);
            *x1 += *x2;
            std::mem::swap(x1, x2);
        *x1 == *x2

let mut x1 = 0;
let mut x2 = 0;
let mut n = 10;

Fib::forward(&mut x1, &mut x2, &mut n);

assert_eq!(x1, 89);
assert_eq!(x2, 144);
assert_eq!(n, 0);

Fib::backwards(&mut x1, &mut x2, &mut n);

assert_eq!(x1, 0);
assert_eq!(x2, 0);
assert_eq!(n, 10);


To keep the code reversible it is necessary to put some limitations on what is possible to do.

Mutating operations

The only operations in this DSL that can cause a mutation are +=, -= and ^= all other mutating operations are disallowed as they cannot be reversed.

Though it is possible to use other operations together with mutating operations for example in a += e. Here a must be a identifier or a dereference of a identifier, but e can be any expression that does not cause a mutation.

Operator Reverse
+= -=
-= +=
^= ^=


Mutable aliasing is not allowed and will cause a runtime error if attempted. This is because a operation with aliasing can cause loss of information and thus making it irreversible. For example a -= a will always cause a to be nullified and thus causing a loss of information.

Function and method calls

At the given time no non-reversible Rust functions or methods are allowed to be called inside of reversible code, this is a something that can be changed since non-mutating functions and methods could be allowed here.


The language as it is now is mostly based upon the Janus formalized in the following paper:

Tetsuo Yokoyama and Robert Glück. 2007. A reversible programming language and its invertible self-interpreter. DOI

You might also like...
An etcd client library for Rust.

etcd An etcd client library for Rust. etcd on crates.io Documentation for the latest crates.io release Running the tests Install Docker and Docker Com

etcd for rust

etcd for Rust An etcd(API v3) client for Rust, and it provides async/await APIs backed by tokio and tonic. Documentation on the library can be found a

Rust bindings for LMDB

lmdb-rs Rust bindings for LMDB Documentation (master branch) Building LMDB is bundled as submodule so update submodules first: git submodule update --

The official MongoDB Rust Driver

MongoDB Rust Driver This repository contains the officially supported MongoDB Rust driver, a client side library that can be used to interact with Mon

Redis library for rust

redis-rs Redis-rs is a high level redis library for Rust. It provides convenient access to all Redis functionality through a very flexible but low-lev

rust wrapper for rocksdb

rust-rocksdb Requirements Clang and LLVM Contributing Feedback and pull requests welcome! If a particular feature of RocksDB is important to you, plea

UnQLite wrapper 1.0 is avaliable for Rust

unqlite A high-level UnQLite database engine wrapper. NOTE: Some of the documents is stolen from UnQLite Official Website. What is UnQLite? UnQLite is

Pure Rust library for Apache ZooKeeper built on MIO

rust-zookeeper Zookeeper client written 100% in Rust This library is intended to be equivalent with the official (low-level) ZooKeeper client which sh

PickleDB-rs is a lightweight and simple key-value store. It is a Rust version for Python's PickleDB

PickleDB PickleDB is a lightweight and simple key-value store written in Rust, heavily inspired by Python's PickleDB PickleDB is fun and easy to use u

  • Add a way to make custom reversible functions

    Add a way to make custom reversible functions

    At the moment functions that have a inverse counterpart are hardcoded, for example forward gets turned into backwards, if it was possible to implement a trait in some way to generalize it would make it easier to extend RRust.

    opened by Erk- 0
  • Add support for rotate

    Add support for rotate

    When rotate_left is used the inverse should be rotate_right and the same the other way around.

    For example

    // ↓ 

    This is likely not enough since rotate is not a mutating operation so a way would be to make our own function along the lines of:

    fn rotate_left(i: &mut u32, n: u32) {
        *i = *i.rotate_left(n);

    And then swap that between left and right in the reverse macro.

    enhancement good first issue 
    opened by Erk- 0
  • Add a

    Add a "@" construct to RRust

    The language Hermes has a construct s1 @ s2 which expands into s1; s2; I[s1]; where I means the inverse of s1. This is a common pattern in the examples of algorithms in the HERMES paper: https://doi.org/10.1016/j.scico.2021.102746

    opened by Erk- 0
Redis re-implemented in Rust.

rsedis Redis re-implemented in Rust. Why? To learn Rust. Use Cases rsedis does not rely on UNIX-specific features. Windows users can run it as a repla

Sebastian Waisbrot 1.6k Jan 6, 2023
A generic connection pool for Rust

r2d2 A generic connection pool for Rust. Documentation Opening a new database connection every time one is needed is both inefficient and can lead to

Steven Fackler 1.2k Jan 8, 2023
An ArangoDB driver for Rust

Rincon Rincon is an ArangoDB driver for Rust. It enables low level access to ArangoDB in a typesafe and Rust idiomatic manner. The name Rincon is deri

Innoave 35 Mar 21, 2021
Cassandra DB native client written in Rust language. Find 1.x versions on https://github.com/AlexPikalov/cdrs/tree/v.1.x Looking for an async version? - Check WIP https://github.com/AlexPikalov/cdrs-async

CDRS CDRS is looking for maintainers CDRS is Apache Cassandra driver written in pure Rust. ?? Looking for an async version? async-std https://github.c

Alex Pikalov 338 Jan 1, 2023
Cassandra (CQL) driver for Rust, using the DataStax C/C++ driver under the covers.

cassandra-cpp This is a maintained Rust project that exposes the DataStax cpp driver at https://github.com/datastax/cpp-driver/ in a somewhat-sane cra

null 93 Jan 7, 2023
CouchDB client-side library for the Rust programming language

Chill Chill is a client-side CouchDB library for the Rust programming language, available on crates.io. It targets Rust Stable. Chill's three chief de

null 35 Jun 26, 2022
Sofa - CouchDB for Rust

Sofa - CouchDB for Rust Documentation Here: http://docs.rs/sofa Installation [dependencies] sofa = "0.6" Description This crate is an interface to Cou

66 Origin 40 Feb 11, 2022
⚡🦀 🧨 make your rust types fit DynamoDB and visa versa

?? ?? dynomite dynomite makes DynamoDB fit your types (and visa versa) Overview Goals ⚡ make writing dynamodb applications in rust a productive experi

Doug Tangren 197 Dec 15, 2022
A Rust client for the ElasticSearch REST API

rs-es Introduction An ElasticSearch client for Rust via the REST API. Targetting ElasticSearch 2.0 and higher. Other clients For later versions of Ela

Ben Ashford 218 Dec 27, 2022
An Elasticsearch REST API client for Rust

elastic elastic is an efficient, modular API client for Elasticsearch written in Rust. The API is targeting the Elastic Stack 7.x. elastic provides st

null 249 Oct 18, 2022