38 releases (stable)

11.0.1 Mar 9, 2021
11.0.0 Jun 3, 2020
10.0.0 Nov 14, 2019
8.1.0 May 15, 2019
0.4.0 Mar 29, 2018

#136 in Operating systems

Download history 43/week @ 2023-06-09 57/week @ 2023-06-16 10/week @ 2023-06-23 80/week @ 2023-06-30 125/week @ 2023-07-07 10/week @ 2023-07-14 13/week @ 2023-07-21 90/week @ 2023-07-28 9/week @ 2023-08-04 49/week @ 2023-08-11 6/week @ 2023-08-18 45/week @ 2023-08-25 13/week @ 2023-09-01 167/week @ 2023-09-08 5991/week @ 2023-09-15 7736/week @ 2023-09-22

14,046 downloads per month
Used in 2 crates




The varlink crate provides support to implement client and server using the varlink protocol.

See http://varlink.org for more information about varlink.

Build Status Crate

More Info


Server and client support for the varlink protocol


To create a varlink server in rust, place your varlink interface definition file in src/. E.g. src/org.example.ping.varlink:

interface org.example.ping

method Ping(ping: string) -> (pong: string)

Then create a build.rs file in your project directory:

extern crate varlink_generator;

fn main() {
                                             /* rustfmt */ true);

For more code generation functions see the generator functions.

Add to your Cargo.toml:

build = "build.rs"
varlink_generator = "<version>"

In your main.rs you can then use:

mod org_example_ping;

and then implement the interface:

struct MyOrgExamplePing;

impl VarlinkInterface for MyOrgExamplePing {
    fn ping(&self, call: &mut dyn Call_Ping, ping: String) -> Result<()> {
        return call.reply(ping);

to implement the interface methods.

If your varlink method is called TestMethod, the rust method to be implemented is called test_method. The first parameter is of type Call_TestMethod, which has the method reply().

fn test_method(&self, call: &mut dyn Call_TestMethod, /* more arguments */) -> Result<()> {
    /* ... */
return call.reply( /* more arguments */ );

A typical server creates a VarlinkService and starts a server via varlink::listen

let args: Vec<_> = std::env::args().collect();
let myorgexampleping = MyOrgExamplePing;
let myorgexampleping_interface = org_example_ping::new(Box::new(myorgexampleping));

let service = varlink::VarlinkService::new(
    "test service",
        // more interfaces ...

varlink::listen(service, &args[1],
    &varlink::ListenConfig {
        idle_timeout: 1,

where args[1] would follow the varlink address specification.

Currently supported address URIs are:

  • TCP tcp: hostname/IP address and port
  • UNIX socket unix:/run/org.example.ftl optional access ;mode=0666 parameter
  • UNIX abstract namespace socket unix:@org.example.ftl (on Linux only)


Setup your project, just like in the server case with a varlink file and a build.rs file.

In your main.rs you can then use:

mod org_example_ping;
use org_example_ping;
let connection = Connection::with_address("unix:/tmp/org.example.ping").unwrap();
let mut ping_service = org_example_ping::VarlinkClient::new(connection);
let reply = ping_service.ping(String::from("Test")).call()?;
assert_eq!(String::from("Test"), reply.pong);

A connection can be established via the connection builder functions. The org_example_ping::VarlinkClient implements org_example_ping::VarlinkClientInterface, which has all the varlink methods (names converted from camel case to lowercase snake case). The PingString() method would be named ping_string().

To iterate over a more call

for reply in my_more_service.test_more(/* params */).more()? { /*...*/ }

The reply struct is placed in a structure named after the method with _Reply appended. So, the reply to the Ping() method in our example is in a struct called Ping_Reply.


~129K SLoC