From 4db97f08e6809f6547a6601d37d2cfbb388365f8 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 19 Jan 2020 20:42:26 +0300 Subject: [PATCH] feat: add features for each type --- itconfig/Cargo.toml | 51 ++++++++++++++++++++++++++++++++++++++++-- itconfig/README.md | 1 + itconfig/src/envstr.rs | 24 +++++++++++++++----- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/itconfig/Cargo.toml b/itconfig/Cargo.toml index c35e8a3..3cebc52 100644 --- a/itconfig/Cargo.toml +++ b/itconfig/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "itconfig" -version = "0.10.0" +version = "0.10.1" authors = ["Dmitriy Pleshevskiy "] description = "Easy build a configs from environment variables and use it in globally." categories = ["config", "web-programming"] @@ -22,6 +22,53 @@ maintenance = { status = "actively-developed" } failure = { version = "0.1.6", features = ["derive"]} [features] -default = ['macro'] +default = ["macro", "numbers", "bool"] macro = [] +numbers = [ + "int", + "uint", + "float" +] + +int = [ + "i8", + "i16", + "i32", + "i64", + "i128", + "isize", +] + +uint = [ + "u8", + "u16", + "u32", + "u64", + "u128", + "usize", +] + +float = [ + "f32", + "f64", +] + +i8 = [] +i16 = [] +i32 = [] +i64 = [] +i128 = [] +isize = [] + +u8 = [] +u16 = [] +u32 = [] +u64 = [] +u128 = [] +usize = [] + +f32 = [] +f64 = [] + +bool = [] diff --git a/itconfig/README.md b/itconfig/README.md index 94445fc..7bd6029 100644 --- a/itconfig/README.md +++ b/itconfig/README.md @@ -96,6 +96,7 @@ fn main() { * [ ] Common configuration for namespace variables + ## License [MIT] © [Ice Temple](https://github.com/icetemple) diff --git a/itconfig/src/envstr.rs b/itconfig/src/envstr.rs index c79c773..05896a0 100644 --- a/itconfig/src/envstr.rs +++ b/itconfig/src/envstr.rs @@ -1,5 +1,4 @@ use std::ops::Deref; -use std::str::FromStr; #[doc(hidden)] @@ -29,10 +28,11 @@ impl ToEnvString for T #[doc(hidden)] macro_rules! from_env_string_numbers_impl { - ($($ty:ty),+) => { + ($($ty:ty => $feature:expr),+) => { $( + #[cfg(feature = $feature)] impl FromEnvString for $ty { - type Err = <$ty as FromStr>::Err; + type Err = <$ty as std::str::FromStr>::Err; #[inline] fn from_env_string(s: &EnvString) -> Result { @@ -44,12 +44,24 @@ macro_rules! from_env_string_numbers_impl { } from_env_string_numbers_impl![ - i8, i16, i32, i64, i128, isize, - u8, u16, u32, u64, u128, usize, - f32, f64 + i8 => "i8", + i16 => "i16", + i32 => "i32", + i64 => "i64", + i128 => "i128", + isize => "isize", + u8 => "u8", + u16 => "u16", + u32 => "u32", + u64 => "u64", + u128 => "u128", + usize => "usize", + f32 => "f32", + f64 => "f64" ]; +#[cfg(feature = "bool")] impl FromEnvString for bool { type Err = ();