Crate varlink [−] [src]
Server 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
:
# Example service
interface org.example.ping
# Returns the same string
method Ping(ping: string) -> (pong: string)
Then create a build.rs
file in your project directory:
extern crate varlink; fn main() { varlink::generator::cargo_build_tosource("src/org.example.ping.varlink", /* rustfmt */ true); }
Add to your Cargo.toml
:
[package]
build = "build.rs"
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 _CallPing, 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 _CallTestMethod
, which has the method reply()
.
fn test_method(&self, call: &mut _CallTestMethod, /* 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( "org.varlink", "test service", "0.1", "http://varlink.org", vec![ Box::new(myorgexampleping_interface), /* more interfaces ...*/ ], ); varlink::listen(service, args[1].clone(), 10, 0);
where args[1] would follow the varlink address specification.
Currently supported address URIs are:
- TCP
tcp:127.0.0.1:12345
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) - executed binary
exec:/usr/bin/org.example.ftl
via socket activation (on Linux only)
Modules
generator |
Generate rust code from varlink interface definition files |
Structs
Call |
Call is a struct, which is passed as the first argument to the interface methods in a derived form. |
Connection | |
Error |
The Error type. |
ErrorInterfaceNotFound | |
ErrorInvalidParameter | |
ErrorMethodNotFound | |
ErrorMethodNotImplemented | |
GetInfoArgs | |
GetInterfaceDescriptionArgs | |
GetInterfaceDescriptionReply | |
MethodCall | |
OrgVarlinkServiceClient | |
Reply |
The structure of a varlink reply. Used to deserialize it into json. |
Request |
The structure of a varlink request. Used to serialize json into it. |
ServiceInfo | |
StringHashSet | |
VarlinkService |
VarlinkService handles all the I/O and dispatches method calls to the registered interfaces. |
Enums
ErrorKind |
The kind of an error. |
Traits
CallTrait |
CallTrait provides convenience methods for the |
Interface |
This trait has to be implemented by any varlink interface implementor. All methods are generated by the varlink-rust-generator, so you don't have to care about them. |
OrgVarlinkServiceInterface | |
ResultExt |
Additional methods for |
VarlinkReply |
Marker trait for the rust code generated by the varlink-rust-generator |
Functions
listen |
|
Type Definitions
Result |
Convenient wrapper around |
StringHashMap |