diff --git a/README.md b/README.md index 4a2ee26..a3ef219 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/itconfig/Cargo.toml b/itconfig/Cargo.toml index c327ec2..15d80d3 100644 --- a/itconfig/Cargo.toml +++ b/itconfig/Cargo.toml @@ -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" } diff --git a/itconfig/src/envstr.rs b/itconfig/src/envstr.rs index 8da5307..efc7838 100644 --- a/itconfig/src/envstr.rs +++ b/itconfig/src/envstr.rs @@ -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 From 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 { + Ok(s.0.clone()) + } +} + +impl FromEnvString for &'static str { + type Err = (); + + fn from_env_string(s: &EnvString) -> Result { + 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 FromEnvString for Vec where T: FromEnvString, @@ -124,44 +174,3 @@ where }) } } - -impl FromEnvString for String { - type Err = (); - - fn from_env_string(s: &EnvString) -> Result { - Ok(s.0.clone()) - } -} - -impl FromEnvString for &'static str { - type Err = (); - - fn from_env_string(s: &EnvString) -> Result { - 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 From 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 - } -} diff --git a/itconfig/src/lib.rs b/itconfig/src/lib.rs index 32a2bb8..2ca2655 100644 --- a/itconfig/src/lib.rs +++ b/itconfig/src/lib.rs @@ -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.