trim_ascii_end

Macro trim_ascii_end 

Source
macro_rules! trim_ascii_end {
    ($s: expr) => { ... };
}
Expand description

Trims ASCII whitespace from the end of a string.

ASCII whitespace characters are space (0x20), tab (0x09), newline (0x0A), vertical tab (0x0B), form feed (0x0C), and carriage return (0x0D).

This macro is const-fn compatible.

ยงExamples

const TRIMMED: &str = const_str::trim_ascii_end!("  hello world  ");
assert_eq!(TRIMMED, "  hello world");

const MIXED: &str = const_str::trim_ascii_end!("hello\tworld\n  \r");
assert_eq!(MIXED, "hello\tworld");

const NO_WHITESPACE: &str = const_str::trim_ascii_end!("hello");
assert_eq!(NO_WHITESPACE, "hello");

// Works in const functions too
const fn process_string(s: &str) -> &str {
    const_str::trim_ascii_end!(s)
}
assert_eq!(process_string("test  "), "test");