Update Rust example
This commit is contained in:
parent
8dd3861388
commit
7524e7c12b
18
README.md
18
README.md
|
@ -59,26 +59,38 @@ use hyperbuild::hyperbuild;
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut code = b"<p> Hello, world! </p>".to_vec();
|
let mut code = b"<p> Hello, world! </p>".to_vec();
|
||||||
|
|
||||||
|
match hyperbuild(&mut code) {
|
||||||
|
Ok(minified_len) => {}
|
||||||
|
Err((error_type, error_position)) => {}
|
||||||
|
};
|
||||||
|
|
||||||
// `hyperbuild_copy` creates a copy instead of minifying in-place.
|
// `hyperbuild_copy` creates a copy instead of minifying in-place.
|
||||||
match hyperbuild_copy(&code) {
|
match hyperbuild_copy(&code) {
|
||||||
Ok(minified) => {}
|
Ok(minified) => {}
|
||||||
Err((error_type, error_position)) => {}
|
Err((error_type, error_position)) => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// `hyperbuild_truncate` minifies a vector in-place, and then truncates the vector to the new minified length.
|
// `hyperbuild_truncate` minifies a vector in-place, and then truncates the vector to the new minified length.
|
||||||
match hyperbuild_truncate(&mut code) {
|
match hyperbuild_truncate(&mut code) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err((error_type, error_position)) => {}
|
Err((error_type, error_position)) => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// `hyperbuild` minifies a slice in place and returns the new minified length but leaves any original code after the minified code intact.
|
// `hyperbuild` minifies a slice in place and returns the new minified length but leaves any original code after the minified code intact.
|
||||||
match hyperbuild(&mut code) {
|
match hyperbuild(&mut code) {
|
||||||
Ok(minified_len) => {}
|
Ok(minified_len) => {}
|
||||||
Err((error_type, error_position)) => {}
|
Err((error_type, error_position)) => {}
|
||||||
};
|
};
|
||||||
// `hyperbuild_friendly_error` is identical to `hyperbuild` except the error is a FriendlyError instead, which includes three fields: `position`, `message`, and `code_context`.
|
|
||||||
|
// `hyperbuild_friendly_error` is identical to `hyperbuild` except the error is a FriendlyError instead.
|
||||||
// `code_context` is a string of a visual representation of the source code with line numbers and position markers to aid in debugging syntax issues, and should be printed.
|
// `code_context` is a string of a visual representation of the source code with line numbers and position markers to aid in debugging syntax issues, and should be printed.
|
||||||
match hyperbuild(&mut code) {
|
match hyperbuild_friendly_error(&mut code) {
|
||||||
Ok(minified_len) => {}
|
Ok(minified_len) => {}
|
||||||
Err((error_type, error_position)) => {}
|
Err(FriendlyError { position, message, code_context }) => {
|
||||||
|
eprintln!("Failed at character {}:", position);
|
||||||
|
eprintln!("{}", message);
|
||||||
|
eprintln!("{}", code_context);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue