Skip to main content

truncate_long

Macro truncate_long 

Source
macro_rules! truncate_long {
    ($query:expr) => { ... };
    ($query:expr,true) => { ... };
}
Expand description

Truncate long strings for logging and error messages purpose.

Returns a format_args! that yields at most 497 characters from the start of the input followed by ... when truncation occurred. Minimal overhead.

If true is the second argument, it evaluates the first argument just once.

§Examples

use tank_core::truncate_long;
let short = "SELECT 1";
assert_eq!(format!("{}", truncate_long!(short)), "SELECT 1\n");
let long = format!("SELECT {}", "X".repeat(600));
let logged = format!("{}", truncate_long!(long));
assert!(logged.starts_with("SELECT XXXXXX"));
assert!(logged.ends_with("...\n"));