JSON — write .txt file in Rust

Ivy Seo
Feb 28, 2021

--

pub fn serialize_writeFile(data : &full_data ) -> Result<bool, modbus::Error> { // 1) takes data 
// this function takes the m7_data object and serializes the contents and saves the results to a text file

// 2) serializes the contents

let some_data = json!({

"logdate" : Utc::now().naive_local(),
"direction": data.job_info.direction,
"job": data.job_info.job_name
});


// 3) saves the results to a text file

let file_generated = File::create("C:/Users/Desktop/jsonData.txt").expect("create .txt file failed"); // file location


let mut file_generated = BufWriter::new(file_generated);
file_generated.write_all(format!("{}", some_data).as_bytes()).expect("write failed");

Ok(true)
}

#GUID#RUST#JSON

--

--