diff --git a/Cargo.toml b/Cargo.toml index fcc1c1ef..914f0b7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,10 +15,9 @@ edition = "2018" maintenance = { status = "actively-developed" } [features] -default = ["toml", "json", "yaml", "hjson", "ini", "ron", "json5"] +default = ["toml", "json", "yaml", "ini", "ron", "json5"] json = ["serde_json"] yaml = ["yaml-rust"] -hjson = ["serde-hjson"] ini = ["rust-ini"] json5 = ["json5_rs"] preserve_order = ["indexmap", "toml/preserve_order", "serde_json/preserve_order", "ron/indexmap"] @@ -32,7 +31,6 @@ nom = "6" toml = { version = "0.5", optional = true } serde_json = { version = "1.0.2", optional = true } yaml-rust = { version = "0.4", optional = true } -serde-hjson = { version = "0.9", default-features = false, optional = true } rust-ini = { version = "0.17", optional = true } ron = { version = "0.6", optional = true } json5_rs = { version = "0.3", optional = true, package = "json5" } diff --git a/README.md b/README.md index 07fcadf3..17498653 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ - Set defaults - Set explicit values (to programmatically override) - - Read from [JSON], [TOML], [YAML], [HJSON], [INI], [RON], [JSON5] files + - Read from [JSON], [TOML], [YAML], [INI], [RON], [JSON5] files - Read from environment - Loosely typed — Configuration values may be read in any supported type, as long as there exists a reasonable conversion - Access nested fields using a formatted path — Uses a subset of JSONPath; currently supports the child ( `redis.port` ) and subscript operators ( `databases[0].name` ) @@ -19,7 +19,6 @@ [JSON]: https://github.com/serde-rs/json [TOML]: https://github.com/toml-lang/toml [YAML]: https://github.com/chyh1990/yaml-rust -[HJSON]: https://github.com/hjson/hjson-rust [INI]: https://github.com/zonyitoo/rust-ini [RON]: https://github.com/ron-rs/ron [JSON5]: https://github.com/callum-oakley/json5-rs @@ -33,7 +32,6 @@ config = "0.11" - `ini` - Adds support for reading INI files - `json` - Adds support for reading JSON files - - `hjson` - Adds support for reading HJSON files - `yaml` - Adds support for reading YAML files - `toml` - Adds support for reading TOML files - `ron` - Adds support for reading RON files diff --git a/src/file/format/hjson.rs b/src/file/format/hjson.rs deleted file mode 100644 index 4b761149..00000000 --- a/src/file/format/hjson.rs +++ /dev/null @@ -1,54 +0,0 @@ -use std::error::Error; - -use crate::map::Map; -use crate::value::{Value, ValueKind}; - -pub fn parse( - uri: Option<&String>, - text: &str, -) -> Result, Box> { - // Parse a JSON object value from the text - // TODO: Have a proper error fire if the root of a file is ever not a Table - let value = from_hjson_value(uri, &serde_hjson::from_str(text)?); - match value.kind { - ValueKind::Table(map) => Ok(map), - - _ => Ok(Map::new()), - } -} - -fn from_hjson_value(uri: Option<&String>, value: &serde_hjson::Value) -> Value { - match *value { - serde_hjson::Value::String(ref value) => Value::new(uri, ValueKind::String(value.clone())), - - serde_hjson::Value::I64(value) => Value::new(uri, ValueKind::Integer(value)), - - serde_hjson::Value::U64(value) => Value::new(uri, ValueKind::Integer(value as i64)), - - serde_hjson::Value::F64(value) => Value::new(uri, ValueKind::Float(value)), - - serde_hjson::Value::Bool(value) => Value::new(uri, ValueKind::Boolean(value)), - - serde_hjson::Value::Object(ref table) => { - let mut m = Map::new(); - - for (key, value) in table { - m.insert(key.clone(), from_hjson_value(uri, value)); - } - - Value::new(uri, ValueKind::Table(m)) - } - - serde_hjson::Value::Array(ref array) => { - let mut l = Vec::new(); - - for value in array { - l.push(from_hjson_value(uri, value)); - } - - Value::new(uri, ValueKind::Array(l)) - } - - serde_hjson::Value::Null => Value::new(uri, ValueKind::Nil), - } -} diff --git a/src/file/format/mod.rs b/src/file/format/mod.rs index 9f6d7d73..b4129e16 100644 --- a/src/file/format/mod.rs +++ b/src/file/format/mod.rs @@ -17,9 +17,6 @@ mod json; #[cfg(feature = "yaml")] mod yaml; -#[cfg(feature = "hjson")] -mod hjson; - #[cfg(feature = "ini")] mod ini; @@ -43,10 +40,6 @@ pub enum FileFormat { #[cfg(feature = "yaml")] Yaml, - /// HJSON (parsed with serde_hjson) - #[cfg(feature = "hjson")] - Hjson, - /// INI (parsed with rust_ini) #[cfg(feature = "ini")] Ini, @@ -75,9 +68,6 @@ lazy_static! { #[cfg(feature = "yaml")] formats.insert(FileFormat::Yaml, vec!["yaml", "yml"]); - #[cfg(feature = "hjson")] - formats.insert(FileFormat::Hjson, vec!["hjson"]); - #[cfg(feature = "ini")] formats.insert(FileFormat::Ini, vec!["ini"]); @@ -119,9 +109,6 @@ impl FileFormat { #[cfg(feature = "yaml")] FileFormat::Yaml => yaml::parse(uri, text), - #[cfg(feature = "hjson")] - FileFormat::Hjson => hjson::parse(uri, text), - #[cfg(feature = "ini")] FileFormat::Ini => ini::parse(uri, text), diff --git a/src/lib.rs b/src/lib.rs index 267e0d8d..98c90b43 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ //! - Environment variables //! - Another Config instance //! - Remote configuration: etcd, Consul -//! - Files: TOML, JSON, YAML, HJSON, INI, RON, JSON5 +//! - Files: TOML, JSON, YAML, INI, RON, JSON5 //! - Manual, programmatic override (via a `.set` method on the Config instance) //! //! Additionally, Config supports: @@ -41,9 +41,6 @@ extern crate serde_json; #[cfg(feature = "yaml")] extern crate yaml_rust; -#[cfg(feature = "hjson")] -extern crate serde_hjson; - #[cfg(feature = "ini")] extern crate ini; diff --git a/tests/datetime.rs b/tests/datetime.rs index 2b0c22d8..6f40948c 100644 --- a/tests/datetime.rs +++ b/tests/datetime.rs @@ -1,7 +1,6 @@ #![cfg(all( feature = "toml", feature = "json", - feature = "hjson", feature = "yaml", feature = "ini", feature = "ron", @@ -35,14 +34,6 @@ fn make() -> Config { "#, FileFormat::Toml, )) - .add_source(File::from_str( - r#" - { - "hjson_datetime": "2017-05-10T02:14:53Z" - } - "#, - FileFormat::Hjson, - )) .add_source(File::from_str( r#" ini_datetime = 2017-05-10T02:14:53Z @@ -80,11 +71,6 @@ fn test_datetime_string() { assert_eq!(&date, "2017-06-12T10:58:30Z"); - // HJSON - let date: String = s.get("hjson_datetime").unwrap(); - - assert_eq!(&date, "2017-05-10T02:14:53Z"); - // INI let date: String = s.get("ini_datetime").unwrap(); @@ -115,11 +101,6 @@ fn test_datetime() { assert_eq!(date, Utc.ymd(2017, 6, 12).and_hms(10, 58, 30)); - // HJSON - let date: DateTime = s.get("hjson_datetime").unwrap(); - - assert_eq!(date, Utc.ymd(2017, 5, 10).and_hms(2, 14, 53)); - // INI let date: DateTime = s.get("ini_datetime").unwrap(); diff --git a/tests/file_hjson.rs b/tests/file_hjson.rs deleted file mode 100644 index 4ac2e120..00000000 --- a/tests/file_hjson.rs +++ /dev/null @@ -1,80 +0,0 @@ -#![cfg(feature = "hjson")] - -extern crate config; -extern crate float_cmp; -extern crate serde; - -#[macro_use] -extern crate serde_derive; - -use std::path::PathBuf; - -use config::*; -use float_cmp::ApproxEqUlps; - -#[derive(Debug, Deserialize)] -struct Place { - name: String, - longitude: f64, - latitude: f64, - favorite: bool, - telephone: Option, - reviews: u64, - creator: Map, - rating: Option, -} - -#[derive(Debug, Deserialize)] -struct Settings { - debug: f64, - production: Option, - place: Place, - #[serde(rename = "arr")] - elements: Vec, -} - -fn make() -> Config { - Config::builder() - .add_source(File::new("tests/Settings", FileFormat::Hjson)) - .build() - .unwrap() -} - -#[test] -fn test_file() { - let c = make(); - - // Deserialize the entire file as single struct - let s: Settings = c.try_into().unwrap(); - - assert!(s.debug.approx_eq_ulps(&1.0, 2)); - assert_eq!(s.production, Some("false".to_string())); - assert_eq!(s.place.name, "Torre di Pisa"); - assert!(s.place.longitude.approx_eq_ulps(&43.7224985, 2)); - assert!(s.place.latitude.approx_eq_ulps(&10.3970522, 2)); - assert_eq!(s.place.favorite, false); - assert_eq!(s.place.reviews, 3866); - assert_eq!(s.place.rating, Some(4.5)); - assert_eq!(s.place.telephone, None); - assert_eq!(s.elements.len(), 10); - assert_eq!(s.elements[3], "4".to_string()); - assert_eq!( - s.place.creator["name"].clone().into_string().unwrap(), - "John Smith".to_string() - ); -} - -#[test] -fn test_error_parse() { - let res = Config::builder() - .add_source(File::new("tests/Settings-invalid", FileFormat::Hjson)) - .build(); - - let path: PathBuf = ["tests", "Settings-invalid.hjson"].iter().collect(); - - assert!(res.is_err()); - assert_eq!( - res.unwrap_err().to_string(), - format!("Found a punctuator where a key name was expected (check your syntax or use quotes if the key name includes {{}}[],: or whitespace) at line 4 column 1 in {}", path.display()) - ); -} diff --git a/tests/legacy/file_hjson.rs b/tests/legacy/file_hjson.rs deleted file mode 100644 index 8801a131..00000000 --- a/tests/legacy/file_hjson.rs +++ /dev/null @@ -1,77 +0,0 @@ -#![cfg(feature = "hjson")] - -extern crate config; -extern crate float_cmp; -extern crate serde; - -use std::path::PathBuf; - -use self::config::*; -use self::float_cmp::ApproxEqUlps; - -#[derive(Debug, Deserialize)] -struct Place { - name: String, - longitude: f64, - latitude: f64, - favorite: bool, - telephone: Option, - reviews: u64, - creator: Map, - rating: Option, -} - -#[derive(Debug, Deserialize)] -struct Settings { - debug: f64, - production: Option, - place: Place, - #[serde(rename = "arr")] - elements: Vec, -} - -fn make() -> Config { - let mut c = Config::default(); - c.merge(File::new("tests/Settings", FileFormat::Hjson)) - .unwrap(); - - c -} - -#[test] -fn test_file() { - let c = make(); - - // Deserialize the entire file as single struct - let s: Settings = c.try_into().unwrap(); - - assert!(s.debug.approx_eq_ulps(&1.0, 2)); - assert_eq!(s.production, Some("false".to_string())); - assert_eq!(s.place.name, "Torre di Pisa"); - assert!(s.place.longitude.approx_eq_ulps(&43.7224985, 2)); - assert!(s.place.latitude.approx_eq_ulps(&10.3970522, 2)); - assert_eq!(s.place.favorite, false); - assert_eq!(s.place.reviews, 3866); - assert_eq!(s.place.rating, Some(4.5)); - assert_eq!(s.place.telephone, None); - assert_eq!(s.elements.len(), 10); - assert_eq!(s.elements[3], "4".to_string()); - assert_eq!( - s.place.creator["name"].clone().into_string().unwrap(), - "John Smith".to_string() - ); -} - -#[test] -fn test_error_parse() { - let mut c = Config::default(); - let res = c.merge(File::new("tests/Settings-invalid", FileFormat::Hjson)); - - let path: PathBuf = ["tests", "Settings-invalid.hjson"].iter().collect(); - - assert!(res.is_err()); - assert_eq!( - res.unwrap_err().to_string(), - format!("Found a punctuator where a key name was expected (check your syntax or use quotes if the key name includes {{}}[],: or whitespace) at line 4 column 1 in {}", path.display()) - ); -} diff --git a/tests/legacy/mod.rs b/tests/legacy/mod.rs index b331e812..cd0a16a5 100644 --- a/tests/legacy/mod.rs +++ b/tests/legacy/mod.rs @@ -1,7 +1,6 @@ pub mod datetime; pub mod errors; pub mod file; -pub mod file_hjson; pub mod file_ini; pub mod file_json; pub mod file_ron;