-
-
Save tumdum/b912c7941a48d9ba5d3b0334d804dbd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{fs::File, io::BufReader, path::PathBuf}; | |
use anyhow::Result; | |
use serde_json::Value; | |
use structopt::StructOpt; | |
#[derive(Debug, StructOpt)] | |
#[structopt()] | |
struct Opt { | |
path: PathBuf, | |
#[structopt(short, long)] | |
buffer: bool, | |
#[structopt(long)] | |
buffer_size: Option<usize>, | |
} | |
fn main() -> Result<()> { | |
let opt = Opt::from_args(); | |
let file = File::open(opt.path)?; | |
let content: Value = match (opt.buffer, opt.buffer_size) { | |
(false, _) => serde_json::from_reader(file)?, | |
(true, None) => serde_json::from_reader(BufReader::new(file))?, | |
(true, Some(n)) => serde_json::from_reader(BufReader::with_capacity(n, file))?, | |
}; | |
dbg!(content.is_object()); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment