#proc-macro #generation #config #code #rocket-web #web-framework #rocket-config

nightly macro rocket-config-codegen

Procedural macros for the rocket-config library

3 releases

0.0.4 Dec 9, 2019
0.0.2 Oct 4, 2019
0.0.1 Oct 4, 2019

#65 in #rocket-web


Used in 2 crates (via rocket-config)

MIT/Apache

8KB
99 lines

rocket-config

rocket-config is a Fairing designed for Rocket, a web framework for Rust (nightly).

#![feature(proc_macro_hygiene)]

#[macro_use] extern crate rocket;
extern crate rocket_config;
#[macro_use] extern crate rocket_config_codegen;

// This will generate the DieselConfiguration struct
// used below.
configuration!("diesel");

use rocket_config::Factory as ConfigurationsFairing;

// Here, `_configuration` contains the parsed configuration
// file "diesel.{json,yml,yaml}"
#[get("/<name>/<age>")]
fn hello(_configuration: DieselConfiguration, name: String, age: u8)
-> String
{
    format!("Hello, {} year old named {}!", age, name)
}

fn main() {
    rocket::ignite()
        .attach(ConfigurationsFairing::new())
        .mount("/hello", routes![hello]).launch();
}

Dependencies

~1.5MB
~37K SLoC