1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Yasec is a Rust library that helps to initialize configuration structure
//! from environment variables.
//! It makes use of custom derive macros to reduce boilerplate.
//!
//! Example
//!
//! ```
//! #[macro_use]
//! extern crate yasec_derive;
//! extern crate yasec;
//!
//! use std::env;
//! use yasec::Yasec;
//!
//! #[derive(Yasec)]
//! struct Config {
//!     #[yasec(from = "DB_HOST")]
//!     pub db_host: String,
//!
//!     #[yasec(from = "DB_PORT")]
//!     pub db_port: Option<u16>,
//!
//!     #[yasec(from = "HTTP_PORT", default = 8080)]
//!     pub http_port: u16,
//! }
//!
//! fn main() {
//!     // We assume that those environment variables are set somewhere outside
//!     env::set_var("DB_HOST", "localhost");
//!     env::set_var("DB_PORT", "5432");
//!
//!     // Initialize config from environment variables
//!     let config = Config::init().unwrap();
//!
//!     assert_eq!(config.db_host, "localhost");
//!     assert_eq!(config.db_port, Some(5432));
//!     assert_eq!(config.http_port, 8080);
//! }
//! ```
//!
//! The library uses `std::str::FromStr` trait to convert environment variables into custom
//! data type. So, if your data type does not implement `std::str::FromStr` the program
//! will not compile.

mod context;
mod error;
mod traits;

pub use context::Context;
pub use error::{Error, ParseError};
pub use traits::Yasec;