Skip to content

Instantly share code, notes, and snippets.


tumdum/ Secret

Created March 17, 2023 07:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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)]
struct Opt {
path: PathBuf,
#[structopt(short, long)]
buffer: bool,
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))?,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment