29 releases (1 stable)
Uses old Rust 2015
1.0.0 | Aug 25, 2018 |
---|---|
0.7.0 | Apr 17, 2017 |
0.6.1 | Mar 27, 2017 |
0.5.5 | Nov 25, 2016 |
0.1.3 | Jul 8, 2015 |
#2 in #charm
22 downloads per month
Used in 2 crates
(via charmhelpers)
50KB
956 lines
Juju
Rust library for interfacing with Juju.
This library makes it easy to write charms in Rust, with the benefits that Rust brings: static typing, minimal dependencies and fun!
Building
This library requires sqlite3-dev to build because of the rusqlite dependency
lib.rs
:
A library to interface with Juju. For more information about Juju see Juju
A hello world Juju charm example in Rust: You will need a working Juju environment for this to function properly. See [Setting up Juju] (https://jujucharms.com/docs/stable/getting-started). After Juju is functioning see What makes a Charm for the base components of a charm.
Our src/main.rs will contain the following:
Examples
#[macro_use]
extern crate juju;
extern crate log;
use log::LogLevel;
fn config_changed()->Result<(), String>{
juju::log("Hello Juju from Rust!", Some(LogLevel::Debug));
return Ok(());
}
fn main(){
let hook_registry: Vec<juju::Hook> = vec![
hook!("config-changed", config_changed)
];
let result = juju::process_hooks(hook_registry);
if result.is_err(){
juju::log(&format!("Hook failed with error: {:?}", result.err()),
Some(LogLevel::Error));
}else{
juju::log("Hook call was successful!", Some(LogLevel::Debug));
}
}
Now you can build with cargo build
and install the binary in the hooks directory.
Create a symlink in the hooks directory with ln -s hello-world config-changed
. Juju will
attempt to run that symlink and our Juju library will map that to our config_changed function.
We can test our hello-world charm by deploying with juju and watching the debug logs. See Deploying a Charm for more information.
You should see a message in juju debug-log like this unit-hello-world-0[6229]: 2015-08-21 16:16:05 INFO unit.hello-world/0.juju-log server.go:254 Hello Juju from Rust!
Dependencies
~26MB
~508K SLoC