This example demonstrates how to interact with a DDlog program from
Rust. It links against the tutorial.dl
example and invokes it using the
Rust API. The complete workflow is as follows:
ddlog rustc
tutorial.dl ------------> tutorial_ddlog -------+-----------> executable
|
rust_api_test------------------------------------
where tutorial_ddlog
is the Rust project generated by the DDlog compiler for the tutorial.dl
program. It contains several crates that must be imported by each Rust client.
This example (rust_api_test
) imports these modules in Cargo.toml
and uses
them from its main module to create several DDlog transactions.
The generated crates are:
-
tutorial_ddlog
- declares
HDDlog
type that serves as a reference to a running DDlog program. enum Relations
- enumerates program relations- several functions that convert between numeric relation id's and symbolic names.
- declares
-
differential_datalog
- contains the DDlog runtime that is the same for all DDlog programs and simply gets copied to each generated DDlog workspace unmodified (this will change in future releases). -
types
- contains Rust types that correspond to user-defined DDlog types, one for eachtypedef
and each relation in the DDlog program.
The code is heavily documented and can be used as a tutorial for understanding the API as well as a template for writing your own DDlog clients.
The Rust API is currently not as ergonomic as it should be and will evolve in future releases of DDlog.