Skip to content

Instantly share code, notes, and snippets.

@tumdum

tumdum/main.rs Secret

Created March 17, 2023 07:49
Show Gist options
  • Save tumdum/b912c7941a48d9ba5d3b0334d804dbd8 to your computer and use it in GitHub Desktop.
Save tumdum/b912c7941a48d9ba5d3b0334d804dbd8 to your computer and use it in GitHub Desktop.
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