Skip to content

Instantly share code, notes, and snippets.

@tumdum

tumdum/main.rs 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
Embed
What would you like to do?
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