feat: add features for each type
This commit is contained in:
parent
e1cbcb7696
commit
4db97f08e6
3 changed files with 68 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "itconfig"
|
||||
version = "0.10.0"
|
||||
version = "0.10.1"
|
||||
authors = ["Dmitriy Pleshevskiy <dmitriy@ideascup.me>"]
|
||||
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 = []
|
||||
|
|
|
@ -96,6 +96,7 @@ fn main() {
|
|||
* [ ] Common configuration for namespace variables
|
||||
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[MIT] © [Ice Temple](https://github.com/icetemple)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use std::ops::Deref;
|
||||
use std::str::FromStr;
|
||||
|
||||
|
||||
#[doc(hidden)]
|
||||
|
@ -29,10 +28,11 @@ impl<T> 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<Self, Self::Err> {
|
||||
|
@ -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 = ();
|
||||
|
||||
|
|
Reference in a new issue