Skip to content

Commit af40101

Browse files
committed
Auto merge of rust-lang#16302 - homersimpsons:patch-1, r=lnicola
line-index: Create README.md Fixes rust-lang#16180
2 parents 6ce3f44 + 0f69276 commit af40101

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/line-index/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# line-index
2+
3+
This crate is developed as part of `rust-analyzer`.
4+
5+
line-index is a library to convert between text offsets and corresponding line/column coordinates.
6+
7+
## Installation
8+
9+
To add this crate to a project simply run `cargo add line-index`.
10+
11+
## Usage
12+
13+
The main structure is `LineIndex`.
14+
15+
It is constructed with an UTF-8 string, but also supports UTF-16 and UTF-32 offsets.
16+
17+
### Example
18+
19+
```rust
20+
use line_index::LineIndex;
21+
22+
let line_index = LineIndex::new("This is a\nmulti-line\ntext.");
23+
line_index.line_col(3.into()); // LineCol { line: 0, col: 3 }
24+
line_index.line_col(13.into()); // LineCol { line: 1, col: 3 }
25+
line_index.offset(LineCol { line: 2, col: 3 }); // Some (24)
26+
```
27+
28+
## SemVer
29+
30+
This crate uses [semver](https://semver.org/) versioning.

0 commit comments

Comments
 (0)