Skip to content

Commit

Permalink
Auto merge of rust-lang#16302 - homersimpsons:patch-1, r=lnicola
Browse files Browse the repository at this point in the history
line-index: Create README.md

Fixes rust-lang#16180
  • Loading branch information
bors committed Jan 7, 2024
2 parents 6ce3f44 + 0f69276 commit af40101
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/line-index/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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

```rust
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](https://semver.org/) versioning.

0 comments on commit af40101

Please sign in to comment.