From 7aed4581979fdfdf2fdf730ef7977fa8d609f008 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 28 Apr 2022 21:16:43 +0200 Subject: [PATCH] prepare for release --- CHANGELOG.md | 3 ++- README.md | 27 ++++++++++++++++----------- benches/bench.rs | 2 +- src/lib.rs | 12 +++++++++++- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9585a00..4fc3cf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 2.0.0 There are many changes, the two formatting functions have been renamed, `format_reader_writer` now takes -a `W` and `R` instead of `&mut BufReader`, it now always adds a trailing newline. There may be a few more +a `W` and `R` instead of `&mut BufReader`, it now always adds a trailing newline. `Indentation::Default` was +renamed to `Indentation::TwoSpaces` and `FourSpaces` and `Tab` were added. There may be a few more small changes. \ No newline at end of file diff --git a/README.md b/README.md index 2c31bdd..e8d9b77 100644 --- a/README.md +++ b/README.md @@ -4,27 +4,32 @@ It formats over 20MB of nested JSON in 60ms. -For the library, look at [docs.rs](https://docs.rs/jsonformat) +## Library crate -## Install +For the library crate, look at [docs.rs](https://docs.rs/jsonformat) + +## Binary Install You need Rust installed on your system `cargo install jsonformat-cli` -## Usage +## Binary Usage ``` +jsonformat-cli 0.2.0 +Nilstrieb +Formats JSON extremely fast + USAGE: - jsonformat [OPTIONS] [input] + jsonformat [OPTIONS] [INPUT] ARGS: - The input file to format - -FLAGS: - -h, --help Prints help information - -V, --version Prints version information + The input file OPTIONS: - -i, --indent Set the indentation used (\s for space, \t for tab) - -o, --output The output file for the formatted json + -h, --help Print help information + -i, --indentation The indentation, s will replaced by a space and t by a tab. + ss is the default + -o, --output The output file + -V, --version Print version information ``` Reads from stdin if no file is supplied. diff --git a/benches/bench.rs b/benches/bench.rs index e750acf..ac805cd 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -1,4 +1,4 @@ -use std::{fs, io, path::PathBuf}; +use std::{fs, path::PathBuf}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use jsonformat::{format, format_reader_writer, Indentation}; diff --git a/src/lib.rs b/src/lib.rs index 12d83ef..172d68b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,8 +14,12 @@ use std::{ /// but nothing is stopping you from doing that. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum Indentation<'a> { - /// Use the default indentation, which is two spaces + /// Fast path for two spaces TwoSpace, + /// Fast path for four spaces + FourSpace, + /// Fast path for tab + Tab, /// Use a custom indentation String Custom(&'a str), } @@ -142,6 +146,12 @@ where Indentation::TwoSpace => { writer.write_all(b" ")?; } + Indentation::FourSpace => { + writer.write_all(b" ")?; + } + Indentation::Tab => { + writer.write_all(b"\t")?; + } Indentation::Custom(indent) => { writer.write_all(indent.as_bytes())?; }