Function minify_html::with_friendly_error[][src]

pub fn with_friendly_error(
    code: &mut [u8],
    cfg: &Cfg
) -> Result<usize, FriendlyError>

Minifies a slice in-place and returns the new minified length. Any original code after the end of the minified code is left intact.

This function is identical to in_place except it returns a FriendlyError on error instead.

FriendlyError has a code_context field, which is a string of a visual representation of the source, with line numbers and position markers to aid in debugging syntax.

Arguments

  • code - A mutable slice of bytes representing the source code to minify.
  • cfg - Configuration object to adjust minification approach.

Examples

use minify_html::{Cfg, FriendlyError, with_friendly_error};

let mut code = b"<p></div>".to_vec();
let cfg = &Cfg {
    minify_js: false,
    minify_css: false,
};
match with_friendly_error(&mut code, cfg) {
    Ok(minified_len) => {}
    Err(FriendlyError { position, message, code_context }) => {
        assert_eq!(position, 3);
        assert_eq!(message, "Unexpected closing tag.");
        assert_eq!(code_context, concat!(
            "1|<p></div>\n",
            ">|   R \n",
        ));
    }
};