wrath 0.1.0

A structured approach to accessing environment variables
Documentation
//! A small example demonstrating typical usage of `wrath`
//!
//! Try running this example and playing with the environment variables to get a
//! feel for how it works.

use std::path::PathBuf;

use wrath::{parser, TryFromEnv};

/// A structure whose values can be parsed from environment variables
#[derive(Debug, TryFromEnv)]
#[wrath(
    // This required attribute key-value pair gives the derive macro information
    // about the error type to generate. The value must contain at least the
    // name thereof.
    error(
        /// This doc comment will appear on the generated type
        // Attributes can also be applied to the type
        #[derive(Debug)]
        // The name of the error type to generate
        EnvError
    ),
)]
struct Env {
    /// Parses a `u32` out of the `FOO` env var via the `FromStr` trait
    ///
    /// This will fail if:
    ///
    /// * `FOO` is unset
    /// * `FOO`'s value is invalid UTF-8
    /// * `FOO`'s value can't be parsed as a `u32`
    #[allow(dead_code)]
    foo: parser::FromStr<u32>,

    /// Parses a `PathBuf` out of the `BAR` env var via the `From` trait
    ///
    /// This will fail if:
    ///
    /// * `BAR` is unset
    #[allow(dead_code)]
    bar: parser::From<PathBuf>,

    /// Parses a `String` out of the `BAZ` env var via `OsString::into_string`
    ///
    /// If `BAZ` is unset, this field will be `None`.
    ///
    /// This will fail if:
    ///
    /// * `BAZ`'s value is invalid UTF-8
    #[allow(dead_code)]
    baz: Option<parser::IntoString>,
}

fn main() {
    println!("{:#?}", Env::try_from_env());
}