Struct line_span::LineSpan[][src]

pub struct LineSpan<'a> { /* fields omitted */ }
Expand description

LineSpan represents a single line. It is possible to get a &str of the line both including and excluding \n and \r\n.

use line_span::LineSpans;

let text = "foo\nbar\r\nbaz";

for span in text.line_spans() {
    println!(
        "{:>2?}: {:?} {:?}",
        span.range(),
        span.as_str(),
        span.as_str_with_ending(),
    );
}

This will output the following:

0.. 3: "foo" "foo\n"
4.. 7: "bar" "bar\r\n"
9..12: "baz" "baz"

Implementations

Returns the byte index of the start of the line.

Returns the byte index of the end of the line, excluding the line ending part \n or \r\n.

To include the line ending part, then use ending.

Returns the byte index of the end of the line, including the line ending part \n or \r\n.

To exclude the line ending part, then use end.

Returns the byte index range of the start and end of the line, excluding the line ending part \n or \r\n.

To include the line ending part, then use range_with_ending.

Returns the byte index range of the start and end of the line, including the line ending part \n or \r\n.

To exclude the line ending part, then use range.

Returns &str of the line, excluding \n and \r\n.

To include the line ending part, then use as_str_with_ending.

Returns &str of the line, including \n and \r\n.

To exclude the line ending part, then use as_str.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Renders start, end, and ending of LineSpan and as_str as "line".

Returns as_str.

The resulting type after dereferencing.

Renders as_str.

Returns as_str.

Returns range.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.