[−][src]Crate rmp_fs
A small lib that help to serialize and deserialize from/to rmp (RustMessagePack) with a file. It does nothing special, just encapsulates rmp_serde in two functions that can be used repeatedly.
#[macro_use] extern crate serde_derive; use rmp_fs::{save_to_rmp, load_from_rmp}; use std::path::Path; // Define a struct of data #[derive(Debug, PartialEq, Deserialize, Serialize)] struct ExampleData { value: i64, message: String, } fn main() { let file_name = Path::new("test_rmp_fs.blob"); let data = ExampleData { value: -123456, message: "Example rmp_fs".to_string() }; // Save to a file it return Result<(), Box<dyn Error>> save_to_rmp(file_name, &data).expect("Fail to save as rmp."); // Load from a file it return Result<T, Box<dyn Error>> let data2: ExampleData =load_from_rmp(file_name).expect("Fail to load from rmp."); println!("{:?}\n{:?}",data,data2); }
Functions
load_from_rmp | Load RustMessagePack format Deserializable data from a file. |
save_to_rmp | Save Serializable data to a file as RustMessagePack format. Note if the file already exist. The existing file is deleted. |