fix(static): fix static feature for macro
This commit is contained in:
parent
7d4c549272
commit
8d460ba24c
4 changed files with 70 additions and 43 deletions
|
@ -1,7 +1,7 @@
|
||||||
# itconfig
|
# itconfig
|
||||||
[![Build Status](https://travis-ci.org/icetemple/itconfig-rs.svg?branch=master)](https://travis-ci.org/icetemple/itconfig-rs)
|
[![Build Status](https://travis-ci.org/icetemple/itconfig-rs.svg?branch=master)](https://travis-ci.org/icetemple/itconfig-rs)
|
||||||
[![Documentation](https://docs.rs/itconfig/badge.svg)](https://docs.rs/itconfig)
|
[![Documentation](https://docs.rs/itconfig/badge.svg)](https://docs.rs/itconfig)
|
||||||
[![Crates.io](https://img.shields.io/badge/crates.io-v0.11.1-orange.svg?longCache=true)](https://crates.io/crates/itconfig)
|
[![Crates.io](https://img.shields.io/badge/crates.io-v0.11.2-orange.svg?longCache=true)](https://crates.io/crates/itconfig)
|
||||||
[![Join the chat at https://gitter.im/icetemple/itconfig-rs](https://badges.gitter.im/icetemple/itconfig-rs.svg)](https://gitter.im/icetemple/itconfig-rs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[![Join the chat at https://gitter.im/icetemple/itconfig-rs](https://badges.gitter.im/icetemple/itconfig-rs.svg)](https://gitter.im/icetemple/itconfig-rs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
Easy build a configs from environment variables and use it in globally.
|
Easy build a configs from environment variables and use it in globally.
|
||||||
|
|
|
@ -14,3 +14,7 @@ tokio = { version = "0.2", features = ["macros"] }
|
||||||
bytes = "0.5"
|
bytes = "0.5"
|
||||||
futures-util = { version = "0.3", default-features = false }
|
futures-util = { version = "0.3", default-features = false }
|
||||||
pretty_env_logger = "0.3"
|
pretty_env_logger = "0.3"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["static"]
|
||||||
|
static = []
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "itconfig"
|
name = "itconfig"
|
||||||
version = "0.11.1"
|
version = "0.11.2"
|
||||||
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"]
|
||||||
|
|
|
@ -301,14 +301,6 @@ macro_rules! __itconfig_invalid_syntax {
|
||||||
`https://docs.rs/itconfig/latest/itconfig/macro.config.html`"
|
`https://docs.rs/itconfig/latest/itconfig/macro.config.html`"
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
(feature "static") => {
|
|
||||||
compile_error!(
|
|
||||||
"Feature `static` is required for enable this macro function.\
|
|
||||||
Please see the `config!` macro docs for more info.\
|
|
||||||
`https://docs.rs/itconfig/latest/itconfig/macro.config.html`"
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -352,6 +344,55 @@ macro_rules! __itconfig_parse_module {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(feature = "static")]
|
||||||
|
#[macro_export]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __itconfig_impl_static_feature {
|
||||||
|
(
|
||||||
|
unparsed_meta = $meta:tt,
|
||||||
|
unparsed_concat = $concat:tt,
|
||||||
|
name = $name:ident,
|
||||||
|
ty = $ty:ty,
|
||||||
|
$(default = $default:expr,)?
|
||||||
|
tokens = $tokens:tt,
|
||||||
|
args = [$($args:tt)*],
|
||||||
|
) => {
|
||||||
|
__itconfig_parse_variables! {
|
||||||
|
current_variable = {
|
||||||
|
unparsed_meta = $meta,
|
||||||
|
meta = [],
|
||||||
|
unparsed_concat = $concat,
|
||||||
|
concat = [],
|
||||||
|
name = $name,
|
||||||
|
ty = $ty,
|
||||||
|
is_static = true,
|
||||||
|
$(default = $default,)?
|
||||||
|
},
|
||||||
|
tokens = $tokens,
|
||||||
|
$($args)*
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(@import_modules) => {
|
||||||
|
use $crate::lazy_static::lazy_static;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(not(feature = "static"))]
|
||||||
|
#[macro_export]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __itconfig_impl_static_feature {
|
||||||
|
($($tt:tt)*) => {
|
||||||
|
compile_error!(
|
||||||
|
"Feature `static` is required for enable this macro function.\
|
||||||
|
Please see the `config!` macro docs for more info.\
|
||||||
|
`https://docs.rs/itconfig/latest/itconfig/macro.config.html`"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
macro_rules! __itconfig_get_ty_or_default {
|
macro_rules! __itconfig_get_ty_or_default {
|
||||||
|
@ -397,23 +438,14 @@ macro_rules! __itconfig_parse_variables {
|
||||||
],
|
],
|
||||||
$($args:tt)*
|
$($args:tt)*
|
||||||
) => {
|
) => {
|
||||||
#[cfg(feature = "static")]
|
__itconfig_impl_static_feature! {
|
||||||
__itconfig_parse_variables! {
|
|
||||||
current_variable = {
|
|
||||||
unparsed_meta = [$(#$meta)*],
|
unparsed_meta = [$(#$meta)*],
|
||||||
meta = [],
|
|
||||||
unparsed_concat = [$($inner)+],
|
unparsed_concat = [$($inner)+],
|
||||||
concat = [],
|
|
||||||
name = $name,
|
name = $name,
|
||||||
ty = String,
|
ty = String,
|
||||||
is_static = true,
|
|
||||||
},
|
|
||||||
tokens = [$($rest)*],
|
tokens = [$($rest)*],
|
||||||
$($args)*
|
args = [$($args)*],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "static"))]
|
|
||||||
__itconfig_invalid_syntax!(feature "static");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Find concatenated variable
|
// Find concatenated variable
|
||||||
|
@ -449,24 +481,15 @@ macro_rules! __itconfig_parse_variables {
|
||||||
],
|
],
|
||||||
$($args:tt)*
|
$($args:tt)*
|
||||||
) => {
|
) => {
|
||||||
#[cfg(feature = "static")]
|
__itconfig_impl_static_feature! {
|
||||||
__itconfig_parse_variables! {
|
|
||||||
current_variable = {
|
|
||||||
unparsed_meta = [$(#$meta)*],
|
unparsed_meta = [$(#$meta)*],
|
||||||
meta = [],
|
|
||||||
unparsed_concat = [],
|
unparsed_concat = [],
|
||||||
concat = [],
|
|
||||||
name = $name,
|
name = $name,
|
||||||
ty = __itconfig_get_ty_or_default!($($ty)?),
|
ty = __itconfig_get_ty_or_default!($($ty)?),
|
||||||
is_static = true,
|
|
||||||
$(default = $default,)?
|
$(default = $default,)?
|
||||||
},
|
|
||||||
tokens = [$($rest)*],
|
tokens = [$($rest)*],
|
||||||
$($args)*
|
args = [$($args)*],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "static"))]
|
|
||||||
__itconfig_invalid_syntax!(feature "static");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Find variable
|
// Find variable
|
||||||
|
@ -664,8 +687,8 @@ macro_rules! __itconfig_impl_namespace {
|
||||||
$(#$meta)*
|
$(#$meta)*
|
||||||
pub mod $mod_name {
|
pub mod $mod_name {
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
#[cfg(feature = "static")]
|
|
||||||
use $crate::lazy_static::lazy_static;
|
__itconfig_impl_static_feature!( @import_modules );
|
||||||
|
|
||||||
$(__itconfig_impl_namespace! {
|
$(__itconfig_impl_namespace! {
|
||||||
variables = $ns_variable,
|
variables = $ns_variable,
|
||||||
|
|
Reference in a new issue