Browse Source

remove: legacy to-json code

dev
Dnomd343 2 years ago
parent
commit
4113507b16
  1. 32
      src/to-json/src/json.rs
  2. 1
      src/to-json/src/lib.rs

32
src/to-json/src/json.rs

@ -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<Format> {
if let Ok(data) = json::from_str::<json::Value>(content) { // try JSON format
return Some(Format::JSON(data));
}
if let Ok(data) = toml::from_str::<toml::Value>(content) { // try TOML format
return Some(Format::TOML(data));
}
if let Ok(data) = yaml::from_str::<yaml::Value>(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
}
}

1
src/to-json/src/lib.rs

@ -1,4 +1,3 @@
mod ffi;
mod json;
mod parser;
mod convert;

Loading…
Cancel
Save