Function line_span::find_line_start [−][src]
pub fn find_line_start(text: &str, index: usize) -> usize
Expand description
Find the start (byte index) of the line, which index
is within.
See also
find_line_range
to find both start and end of a line.find_line_end
to find the end of the line.find_next_line_start
to find the start of the next line.find_prev_line_start
to find the start of the previous line.
Panics
Panics if index
is out of bounds.
Example
let text = "foo\nbar\nbaz";
let i = 5; // 'a'
let start = line_span::find_line_start(text, i);
assert_eq!(start, 4);
assert_eq!(&text[start..], "bar\nbaz");