chore: mark json array as deprecated
This commit is contained in:
parent
c3caa22b94
commit
c4573bfc48
4 changed files with 58 additions and 48 deletions
|
@ -128,7 +128,6 @@ cargo test --all-features
|
||||||
|
|
||||||
* **default** - ["primitives"]
|
* **default** - ["primitives"]
|
||||||
* **macro** - Activates `config!` macros for easy configure web application.
|
* **macro** - Activates `config!` macros for easy configure web application.
|
||||||
* **array** - Add EnvString impl for vector type (uses optional `serde_json` package).
|
|
||||||
* **primitives** - Group for features: `numbers` and `bool`.
|
* **primitives** - Group for features: `numbers` and `bool`.
|
||||||
* **numbers** - Group for features: `int`, `uint` and `float`.
|
* **numbers** - Group for features: `int`, `uint` and `float`.
|
||||||
* **int** - Group for features: `i8`, `i16`, `i32`, `i64`, `i128` and `isize`.
|
* **int** - Group for features: `i8`, `i16`, `i32`, `i64`, `i128` and `isize`.
|
||||||
|
@ -149,6 +148,7 @@ cargo test --all-features
|
||||||
* **f32** - impl EnvString for `f32` type
|
* **f32** - impl EnvString for `f32` type
|
||||||
* **f64** - impl EnvString for `f64` type
|
* **f64** - impl EnvString for `f64` type
|
||||||
* **bool** - impl EnvString for `bool` type
|
* **bool** - impl EnvString for `bool` type
|
||||||
|
* **json_array** - Add EnvString impl for vector type (uses optional `serde_json` package). ⚠ **_DEPRECATED_**
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
|
@ -26,8 +26,6 @@ default = ["primitives"]
|
||||||
|
|
||||||
macro = ["itconfig-macro"]
|
macro = ["itconfig-macro"]
|
||||||
|
|
||||||
array = ["serde_json"]
|
|
||||||
|
|
||||||
primitives = ["numbers", "bool"]
|
primitives = ["numbers", "bool"]
|
||||||
numbers = ["int", "uint", "float"]
|
numbers = ["int", "uint", "float"]
|
||||||
int = ["i8", "i16", "i32", "i64", "i128", "isize"]
|
int = ["i8", "i16", "i32", "i64", "i128", "isize"]
|
||||||
|
@ -53,6 +51,9 @@ f64 = []
|
||||||
|
|
||||||
bool = []
|
bool = []
|
||||||
|
|
||||||
|
# deprecated since 1.1
|
||||||
|
json_array = ["serde_json"]
|
||||||
|
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "icetemple/itconfig-rs" }
|
travis-ci = { repository = "icetemple/itconfig-rs" }
|
||||||
|
|
|
@ -1,5 +1,30 @@
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
/// Wrapper under String type.
|
||||||
|
///
|
||||||
|
/// When we read the environment variable, we automatically convert the value
|
||||||
|
/// to EnvString and then convert it to your expected type.
|
||||||
|
///
|
||||||
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
pub struct EnvString(String);
|
||||||
|
|
||||||
|
impl<T> From<T> for EnvString
|
||||||
|
where
|
||||||
|
T: ToEnvString,
|
||||||
|
{
|
||||||
|
fn from(val: T) -> Self {
|
||||||
|
val.to_env_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for EnvString {
|
||||||
|
type Target = String;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A trait for converting value to EnvString.
|
/// A trait for converting value to EnvString.
|
||||||
///
|
///
|
||||||
/// This trait automatically implemented for any type which implements the
|
/// This trait automatically implemented for any type which implements the
|
||||||
|
@ -94,15 +119,40 @@ impl FromEnvString for bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
impl FromEnvString for String {
|
||||||
#[cfg(feature = "array")]
|
type Err = ();
|
||||||
|
|
||||||
|
fn from_env_string(s: &EnvString) -> Result<Self, Self::Err> {
|
||||||
|
Ok(s.0.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromEnvString for &'static str {
|
||||||
|
type Err = ();
|
||||||
|
|
||||||
|
fn from_env_string(s: &EnvString) -> Result<Self, Self::Err> {
|
||||||
|
Ok(Box::leak(s.0.clone().into_boxed_str()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//===========================================================================//
|
||||||
|
// DEPRECATED //
|
||||||
|
//===========================================================================//
|
||||||
|
|
||||||
|
/// Error type for json array implementation
|
||||||
|
#[cfg(feature = "json_array")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[deprecated(since = "1.1.0")]
|
||||||
pub enum ArrayEnvError {
|
pub enum ArrayEnvError {
|
||||||
|
/// Invalid type.
|
||||||
InvalidType,
|
InvalidType,
|
||||||
|
|
||||||
|
/// Failed to parse environment variable
|
||||||
FailedToParse,
|
FailedToParse,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "array")]
|
#[cfg(feature = "json_array")]
|
||||||
|
#[allow(deprecated)]
|
||||||
impl<T> FromEnvString for Vec<T>
|
impl<T> FromEnvString for Vec<T>
|
||||||
where
|
where
|
||||||
T: FromEnvString,
|
T: FromEnvString,
|
||||||
|
@ -124,44 +174,3 @@ where
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromEnvString for String {
|
|
||||||
type Err = ();
|
|
||||||
|
|
||||||
fn from_env_string(s: &EnvString) -> Result<Self, Self::Err> {
|
|
||||||
Ok(s.0.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromEnvString for &'static str {
|
|
||||||
type Err = ();
|
|
||||||
|
|
||||||
fn from_env_string(s: &EnvString) -> Result<Self, Self::Err> {
|
|
||||||
Ok(Box::leak(s.0.clone().into_boxed_str()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Wrapper under String type.
|
|
||||||
///
|
|
||||||
/// When we read the environment variable, we automatically convert the value
|
|
||||||
/// to EnvString and then convert it to your expected type.
|
|
||||||
///
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
|
||||||
pub struct EnvString(String);
|
|
||||||
|
|
||||||
impl<T> From<T> for EnvString
|
|
||||||
where
|
|
||||||
T: ToEnvString,
|
|
||||||
{
|
|
||||||
fn from(val: T) -> Self {
|
|
||||||
val.to_env_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for EnvString {
|
|
||||||
type Target = String;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -113,7 +113,6 @@
|
||||||
//!
|
//!
|
||||||
//! * **default** - ["primitives"]
|
//! * **default** - ["primitives"]
|
||||||
//! * **macro** - Activates `config!` macros for easy configure web application.
|
//! * **macro** - Activates `config!` macros for easy configure web application.
|
||||||
//! * **array** - Add EnvString impl for vector type (uses optional `serde_json` package).
|
|
||||||
//! * **primitives** - Group for features: `numbers` and `bool`.
|
//! * **primitives** - Group for features: `numbers` and `bool`.
|
||||||
//! * **numbers** - Group for features: `int`, `uint` and `float`.
|
//! * **numbers** - Group for features: `int`, `uint` and `float`.
|
||||||
//! * **int** - Group for features: `i8`, `i16`, `i32`, `i64`, `i128` and `isize`.
|
//! * **int** - Group for features: `i8`, `i16`, `i32`, `i64`, `i128` and `isize`.
|
||||||
|
@ -134,6 +133,7 @@
|
||||||
//! * **f32** - impl EnvString for `f32` type
|
//! * **f32** - impl EnvString for `f32` type
|
||||||
//! * **f64** - impl EnvString for `f64` type
|
//! * **f64** - impl EnvString for `f64` type
|
||||||
//! * **bool** - impl EnvString for `bool` type
|
//! * **bool** - impl EnvString for `bool` type
|
||||||
|
//! * **json_array** - Add EnvString impl for vector type (uses optional `serde_json` package). ⚠ **_DEPRECATED_**
|
||||||
//!
|
//!
|
||||||
|
|
||||||
// Rustc lints.
|
// Rustc lints.
|
||||||
|
|
Reference in a new issue