File: simple.rs

package info (click to toggle)
rust-line-numbers 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 124 kB
  • sloc: makefile: 4
file content (17 lines) | stat: -rw-r--r-- 415 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use line_numbers::LinePositions;

fn main() {
    let s = "foo\nbar\nbaz\n";
    let s_lines: Vec<_> = s.lines().collect();

    let line_positions = LinePositions::from(s);

    let offset = 5;
    let line_num = line_positions.from_offset(offset);
    println!(
        "Offset {} is on line {}, which has the text {:?}.",
        offset,
        line_num.display(),
        s_lines[line_num.as_usize()]
    );
}