Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created March 23, 2015 23:06
Show Gist options
  • Save adamhjk/dcfadb3525bc52d1f34a to your computer and use it in GitHub Desktop.
Save adamhjk/dcfadb3525bc52d1f34a to your computer and use it in GitHub Desktop.
Chef Style DSL in Rust
// This code actually works, and does the equiv to what Chef code would do.
// It also works as a 'reader' for things, so you can get the data back
// when you as for it.
#[macro_use] extern crate chef;
fn cleaner() {
let file = file_r!{"/etc/passwd");
// Would print Some(0)
println!("file owner: {:?}", file.owner());
// A create action
file_r!([create] "/tmp/params_with_action.txt",
set_owner => Some(1)
set_group => Some(1));
}
fn main() {
let single = file_r!("/tmp/single.txt");
println!("Single {:?}", single);
let with_params = file_r!("/tmp/with_params.txt",
set_owner => Some(1)
set_group => Some(1));
println!("With Params {:?}", with_params);
let single_with_action = file_r!([create] "/tmp/single_with_action.txt");
println!("Action {:?}", single_with_action);
let params_with_action = file_r!([create] "/tmp/params_with_action.txt",
set_owner => Some(1)
set_group => Some(1));
println!("Action with Params {:?}", params_with_action);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment