Browse Source

perf: parser function

dev
Dnomd343 2 years ago
parent
commit
d995aec200
  1. 6
      src/to-json/src/convert.rs
  2. 2
      src/to-json/src/ffi.rs

6
src/to-json/src/convert.rs

@ -2,9 +2,9 @@ use crate::parser::{parser, Value};
fn json_convert(content: &str) -> Result<String, String> { // convert to JSON format
let data = match parser(content)? {
Value::JSON(_json) => serde_json::to_string(&_json),
Value::YAML(_yaml) => serde_json::to_string(&_yaml),
Value::TOML(_toml) => serde_json::to_string(&_toml),
Value::JSON(json) => serde_json::to_string(&json),
Value::YAML(yaml) => serde_json::to_string(&yaml),
Value::TOML(toml) => serde_json::to_string(&toml),
};
match data {
Ok(data) => Ok(data),

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

@ -12,7 +12,7 @@ unsafe fn load_c_string(ptr: *const c_char) -> String { // load string from c-st
}
#[no_mangle]
pub unsafe extern "C" fn free_rust_string(ptr: *const c_char) {
pub unsafe extern "C" fn free_rust_string(ptr: *const c_char) { // free string memory
let _ = CString::from_raw(ptr as *mut _);
}

Loading…
Cancel
Save