Macro split_lines

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

Returns an array of the lines in a string.

Lines are split by LF (\n) or CRLF (\r\n).

Line terminators are not included in the returned array.

The final line ending is optional. A string that ends with a final line ending will return the same lines as an otherwise identical string without a final line ending.

This macro is const-context only.

See also str::lines

ยงExamples

const TEXT: &str = "foo\r\nbar\n\nbaz\r";
const LINES_ARRAY: [&str;4] = const_str::split_lines!(TEXT);
const LINES_SLICE: &[&str] = &const_str::split_lines!(TEXT);

assert_eq!(LINES_ARRAY, LINES_SLICE);
assert_eq!(LINES_SLICE, &["foo", "bar", "", "baz\r"]);
const TEXT1: &str = "1\r\n2\r\n3\r\n";
const TEXT2: &str = "1\n2\n3\n";
const TEXT3: &str = "1\n2\n3";
const LINES1: &[&str] = &const_str::split_lines!(TEXT1);
const LINES2: &[&str] = &const_str::split_lines!(TEXT2);
const LINES3: &[&str] = &const_str::split_lines!(TEXT3);
assert_eq!(LINES1, LINES2);
assert_eq!(LINES2, LINES3);