diff --git a/src/to-json/src/json.rs b/src/to-json/src/json.rs deleted file mode 100644 index 83efc4c..0000000 --- a/src/to-json/src/json.rs +++ /dev/null @@ -1,32 +0,0 @@ -use serde_json as json; -use serde_yaml as yaml; - -enum Format { - JSON(json::Value), - YAML(yaml::Value), - TOML(toml::Value), -} - -fn parser(content: &str) -> Option { - if let Ok(data) = json::from_str::(content) { // try JSON format - return Some(Format::JSON(data)); - } - if let Ok(data) = toml::from_str::(content) { // try TOML format - return Some(Format::TOML(data)); - } - if let Ok(data) = yaml::from_str::(content) { // try YAML format - return Some(Format::YAML(data)); - } - return None; // parse failed -} - -pub fn to_json(content: &str) -> String { // convert to JSON format - match parser(content) { - Some(data) => match data { - Format::JSON(dat) => json::to_string(&dat).unwrap(), - Format::YAML(dat) => json::to_string(&dat).unwrap(), - Format::TOML(dat) => json::to_string(&dat).unwrap(), - }, - None => String::from(""), // failed -> empty string - } -} diff --git a/src/to-json/src/lib.rs b/src/to-json/src/lib.rs index ce4d1e6..768c005 100644 --- a/src/to-json/src/lib.rs +++ b/src/to-json/src/lib.rs @@ -1,4 +1,3 @@ mod ffi; -mod json; mod parser; mod convert;