chore: mark json array as deprecated

This commit is contained in:
Dmitriy Pleshevskiy 2021-04-16 01:12:35 +03:00
parent c3caa22b94
commit c4573bfc48
4 changed files with 58 additions and 48 deletions

View File

@ -128,7 +128,6 @@ cargo test --all-features
* **default** - ["primitives"]
* **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`.
* **numbers** - Group for features: `int`, `uint` and `float`.
* **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
* **f64** - impl EnvString for `f64` type
* **bool** - impl EnvString for `bool` type
* **json_array** - Add EnvString impl for vector type (uses optional `serde_json` package). ⚠ **_DEPRECATED_**
## License

View File

@ -26,8 +26,6 @@ default = ["primitives"]
macro = ["itconfig-macro"]
array = ["serde_json"]
primitives = ["numbers", "bool"]
numbers = ["int", "uint", "float"]
int = ["i8", "i16", "i32", "i64", "i128", "isize"]
@ -53,6 +51,9 @@ f64 = []
bool = []
# deprecated since 1.1
json_array = ["serde_json"]
[badges]
travis-ci = { repository = "icetemple/itconfig-rs" }

View File

@ -1,5 +1,30 @@
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.
///
/// This trait automatically implemented for any type which implements the
@ -94,15 +119,40 @@ impl FromEnvString for bool {
}
}
#[doc(hidden)]
#[cfg(feature = "array")]
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()))
}
}
//===========================================================================//
// DEPRECATED //
//===========================================================================//
/// Error type for json array implementation
#[cfg(feature = "json_array")]
#[derive(Debug)]
#[deprecated(since = "1.1.0")]
pub enum ArrayEnvError {
/// Invalid type.
InvalidType,
/// Failed to parse environment variable
FailedToParse,
}
#[cfg(feature = "array")]
#[cfg(feature = "json_array")]
#[allow(deprecated)]
impl<T> FromEnvString for Vec<T>
where
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
}
}

View File

@ -113,7 +113,6 @@
//!
//! * **default** - ["primitives"]
//! * **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`.
//! * **numbers** - Group for features: `int`, `uint` and `float`.
//! * **int** - Group for features: `i8`, `i16`, `i32`, `i64`, `i128` and `isize`.
@ -134,6 +133,7 @@
//! * **f32** - impl EnvString for `f32` type
//! * **f64** - impl EnvString for `f64` type
//! * **bool** - impl EnvString for `bool` type
//! * **json_array** - Add EnvString impl for vector type (uses optional `serde_json` package). ⚠ **_DEPRECATED_**
//!
// Rustc lints.