Integrate the rust client with c code

If you already have an existing code base written in c and want to integrate tnnl into it, we’ve provided a minimal example for that.

Download the latest rust crate

curl -L 'https://crates.io/api/v1/crates/tnnl/0.1.16/download'  | tar -zxf -

Have a look at the provided example in example/c-interop. There you’ll find a Makefile and main.c file.

Before you can build the c-code, you’ll need to build the rust-library first.

If you haven’t already, get the rust compiler and the build tool cargo. You’ll find instructions under www.rust-lang.org/learn/get-started.

Then navigate to the main directory, where the Cargo.toml file is and build the tnnl rust client with

cargo build

You’ll now find a static library (with debug symbols) in target/debug/libtnnl.a.

You can now go back into example/c-interop and run make debug to link against the rust library you’ve just compiled.

The example runs the tnnl client and expects a valid tnnl token to be in environment variable $TOKEN.

If you don’t have a tnnl token, you can get a temporary one here.

So for example run the client like this:

TOKEN=tROkPuLQKuQfBUlaU6c6 ./main

It’s output should look like this:

user@host:~/client-rust/example/c-interop/ > TOKEN=tROkPuLQKuQfBUlaU6c6 ./main
[*] using rule:
 |  return { host: host, port: port };
 |  
[*] logged in