Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate serde_json;
- extern crate bson;
- use std::fs::File;
- use std::path::Path;
- use serde_json::{Value, Error};
- use std::vec::Vec;
- fn read_argument_from_file<P: AsRef<Path>>(path: P) -> Value {
- // Open the file in read-only mode.
- let file = File::open(path).unwrap();
- // Read the JSON contents of the file as an instance of `User`.
- let v: Value = serde_json::from_reader(file).unwrap();
- // Return the `User`.
- v
- }
- fn main() {
- println!("Hello, world!");
- let u = read_argument_from_file("test.json");
- println!("{:?}", u);
- let b = bson::to_bson(&u).unwrap();
- let mut res: Vec<u8> = Vec::new();
- let bytes = bson::encode_document(&mut res, &b.).unwrap();
- println!("{:?}", &b);
- }
Add Comment
Please, Sign In to add comment