feat: add features for each type

This commit is contained in:
Dmitriy Pleshevskiy 2020-01-19 20:42:26 +03:00
parent e1cbcb7696
commit 4db97f08e6
3 changed files with 68 additions and 8 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "itconfig" name = "itconfig"
version = "0.10.0" version = "0.10.1"
authors = ["Dmitriy Pleshevskiy <dmitriy@ideascup.me>"] authors = ["Dmitriy Pleshevskiy <dmitriy@ideascup.me>"]
description = "Easy build a configs from environment variables and use it in globally." description = "Easy build a configs from environment variables and use it in globally."
categories = ["config", "web-programming"] categories = ["config", "web-programming"]
@ -22,6 +22,53 @@ maintenance = { status = "actively-developed" }
failure = { version = "0.1.6", features = ["derive"]} failure = { version = "0.1.6", features = ["derive"]}
[features] [features]
default = ['macro'] default = ["macro", "numbers", "bool"]
macro = [] 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 = []

View file

@ -96,6 +96,7 @@ fn main() {
* [ ] Common configuration for namespace variables * [ ] Common configuration for namespace variables
## License ## License
[MIT] © [Ice Temple](https://github.com/icetemple) [MIT] © [Ice Temple](https://github.com/icetemple)

View file

@ -1,5 +1,4 @@
use std::ops::Deref; use std::ops::Deref;
use std::str::FromStr;
#[doc(hidden)] #[doc(hidden)]
@ -29,10 +28,11 @@ impl<T> ToEnvString for T
#[doc(hidden)] #[doc(hidden)]
macro_rules! from_env_string_numbers_impl { macro_rules! from_env_string_numbers_impl {
($($ty:ty),+) => { ($($ty:ty => $feature:expr),+) => {
$( $(
#[cfg(feature = $feature)]
impl FromEnvString for $ty { impl FromEnvString for $ty {
type Err = <$ty as FromStr>::Err; type Err = <$ty as std::str::FromStr>::Err;
#[inline] #[inline]
fn from_env_string(s: &EnvString) -> Result<Self, Self::Err> { fn from_env_string(s: &EnvString) -> Result<Self, Self::Err> {
@ -44,12 +44,24 @@ macro_rules! from_env_string_numbers_impl {
} }
from_env_string_numbers_impl![ from_env_string_numbers_impl![
i8, i16, i32, i64, i128, isize, i8 => "i8",
u8, u16, u32, u64, u128, usize, i16 => "i16",
f32, f64 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 { impl FromEnvString for bool {
type Err = (); type Err = ();