Guest User

Untitled

a guest
Aug 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. extern crate serde_json;
  2. extern crate bson;
  3.  
  4. use std::fs::File;
  5. use std::path::Path;
  6. use serde_json::{Value, Error};
  7. use std::vec::Vec;
  8.  
  9.  
  10. fn read_argument_from_file<P: AsRef<Path>>(path: P) -> Value {
  11. // Open the file in read-only mode.
  12. let file = File::open(path).unwrap();
  13.  
  14. // Read the JSON contents of the file as an instance of `User`.
  15. let v: Value = serde_json::from_reader(file).unwrap();
  16.  
  17. // Return the `User`.
  18. v
  19. }
  20.  
  21. fn main() {
  22. println!("Hello, world!");
  23. let u = read_argument_from_file("test.json");
  24. println!("{:?}", u);
  25. let b = bson::to_bson(&u).unwrap();
  26. let mut res: Vec<u8> = Vec::new();
  27. let bytes = bson::encode_document(&mut res, &b.).unwrap();
  28. println!("{:?}", &b);
  29. }
Add Comment
Please, Sign In to add comment