trim_ascii_start

Macro trim_ascii_start 

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

Trims ASCII whitespace from the start 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_start!("  hello world  ");
assert_eq!(TRIMMED, "hello world  ");

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

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

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