Browse Source

update: to_json file structure

dev
Dnomd343 2 years ago
parent
commit
3661bcfce7
  1. 2
      src/to-json/src/ffi.rs
  2. 9
      src/to-json/src/json.rs
  3. 2
      src/to-json/src/lib.rs
  4. 2
      src/to-json/src/tests.rs

2
src/to-json/src/ffi.rs

@ -1,4 +1,4 @@
use crate::convert::to_json; use crate::json::to_json;
use std::ffi::{c_char, CStr, CString}; use std::ffi::{c_char, CStr, CString};
fn to_c_string(string: String) -> *const c_char { // fetch c-style ptr of string fn to_c_string(string: String) -> *const c_char { // fetch c-style ptr of string

9
src/to-json/src/convert.rs → src/to-json/src/json.rs

@ -1,10 +1,11 @@
use serde_json as json;
use crate::parser::{parser, Value}; use crate::parser::{parser, Value};
fn json_convert(content: &str) -> Result<String, String> { // convert to JSON format fn json_convert(content: &str) -> Result<String, String> { // convert to JSON format
let data = match parser(content)? { let data = match parser(content)? {
Value::JSON(json) => serde_json::to_string(&json), Value::JSON(_json) => json::to_string(&_json),
Value::YAML(yaml) => serde_json::to_string(&yaml), Value::YAML(_yaml) => json::to_string(&_yaml),
Value::TOML(toml) => serde_json::to_string(&toml), Value::TOML(_toml) => json::to_string(&_toml),
}; };
match data { match data {
Ok(data) => Ok(data), Ok(data) => Ok(data),
@ -15,6 +16,6 @@ fn json_convert(content: &str) -> Result<String, String> { // convert to JSON fo
pub fn to_json(content: &str) -> Option<String> { // to JSON string pub fn to_json(content: &str) -> Option<String> { // to JSON string
match json_convert(content) { match json_convert(content) {
Ok(data) => Some(data), Ok(data) => Some(data),
Err(_) => None, Err(_) => None, // convert failed
} }
} }

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

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

2
src/to-json/src/tests.rs

@ -1,4 +1,4 @@
use crate::convert::to_json; use crate::json::to_json;
#[allow(dead_code)] #[allow(dead_code)]
const JSON_TEST_CONTENT: &str = r#" const JSON_TEST_CONTENT: &str = r#"

Loading…
Cancel
Save