4 releases

0.1.2 Oct 18, 2024
0.1.1 Dec 12, 2023
0.1.0 Jul 3, 2023
0.1.0-pre.1 May 7, 2023

#59 in Text processing

Download history 27205/week @ 2025-09-23 24952/week @ 2025-09-30 25877/week @ 2025-10-07 25665/week @ 2025-10-14 28021/week @ 2025-10-21 30896/week @ 2025-10-28 26328/week @ 2025-11-04 19985/week @ 2025-11-11 24483/week @ 2025-11-18 26464/week @ 2025-11-25 23210/week @ 2025-12-02 21573/week @ 2025-12-09 23154/week @ 2025-12-16 20420/week @ 2025-12-23 18391/week @ 2025-12-30 30013/week @ 2026-01-06

96,695 downloads per month
Used in 54 crates (18 directly)

MIT/Apache

28KB
526 lines

See LineIndex.


line-index

This crate is developed as part of rust-analyzer.

line-index is a library to convert between text offsets and corresponding line/column coordinates.

Installation

To add this crate to a project simply run cargo add line-index.

Usage

The main structure is LineIndex.

It is constructed with an UTF-8 string, but also supports UTF-16 and UTF-32 offsets.

Example

use line_index::LineIndex;

let line_index = LineIndex::new("This is a\nmulti-line\ntext.");
line_index.line_col(3.into()); // LineCol { line: 0, col: 3 }
line_index.line_col(13.into()); // LineCol { line: 1, col: 3 }
line_index.offset(LineCol { line: 2, col: 3 }); // Some (24)

SemVer

This crate uses semver versioning.

Dependencies

~38KB