mirror of https://github.com/dnomd343/ClearDNS
Dnomd343
2 years ago
2 changed files with 0 additions and 33 deletions
@ -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,4 +1,3 @@ |
|||
mod ffi; |
|||
mod json; |
|||
mod parser; |
|||
mod convert; |
|||
|
Loading…
Reference in new issue