From 693c84756350c533b5c8dfaa931b22b9d78f1f2f Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Tue, 25 Aug 2020 00:36:27 +1000 Subject: [PATCH] Add documentation comments to Rust API --- README.md | 44 +----------------- src/cfg/mod.rs | 9 ++++ src/err.rs | 10 +++- src/lib.rs | 124 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 72fa12a..79b696b 100644 --- a/README.md +++ b/README.md @@ -51,49 +51,7 @@ If the `js-esbuild` feature is not enabled, `cfg.minify_js` will have no effect. ##### Use -```rust -use minify_html::{Cfg, Error, FriendlyError, in_place, copy, with_friendly_error, truncate}; - -fn main() { - let mut code = b"

Hello, world!

".to_vec(); - let cfg = &Cfg { - minify_js: false, - }; - - // Minifies a slice in-place and returns the new minified length, - // but leaves any original code after the minified code intact. - match in_place(&mut code, cfg) { - Ok(minified_len) => {} - Err(Error { error_type, position }) => {} - }; - - // Creates a vector copy containing only minified code - // instead of minifying in-place. - match copy(&code, cfg) { - Ok(minified) => {} - Err(Error { error_type, position }) => {} - }; - - // Minifies a vector in-place, and then truncates the - // vector to the new minified length. - match truncate(&mut code, cfg) { - Ok(()) => {} - Err(Error { error_type, position }) => {} - }; - - // Identical to `in_place` except with FriendlyError instead. - // `code_context` is a string of a visual representation of the source, - // with line numbers and position markers to aid in debugging syntax. - match with_friendly_error(&mut code, cfg) { - Ok(minified_len) => {} - Err(FriendlyError { position, message, code_context }) => { - eprintln!("Failed at character {}:", position); - eprintln!("{}", message); - eprintln!("{}", code_context); - } - }; -} -``` +Check out the [docs](https://docs.rs/minify-html) for API and usage examples. diff --git a/src/cfg/mod.rs b/src/cfg/mod.rs index 59c8d44..7c448a2 100644 --- a/src/cfg/mod.rs +++ b/src/cfg/mod.rs @@ -1,3 +1,12 @@ +/// Configuration settings that can be adjusted and passed to a minification function to change the +/// minification approach. pub struct Cfg { + /// If enabled, JavaScript in `