stream-locate-converter

Crates.iostream-locate-converter
lib.rsstream-locate-converter
version0.1.2
sourcesrc
created_at2024-07-30 19:10:27.21179
updated_at2024-07-31 14:39:59.368637
descriptionA Stream reader which can convert between byte offset and line-column numbers. Support any type which implements io::Read.
homepage
repositoryhttps://github.com/ireina7/stream-locate-converter
max_upload_size
id1320243
size11,727
Ireina (ireina7)

documentation

README

stream-locate-converter

Reader offset and line-column location converter.
A Stream reader which can convert between byte offset and line-column numbers. Support any type which implements io::Read.

Example

use stream_locate_converter::Stream;
use stream_locate_converter::location;
use std::fs;

fn main() -> io::Result<()> {
  let file = fs::File::open("foo.rs")?;
  let mut stream = Stream::from(file);

  let offset = location::Offset::new(20);
  let line_index = stream.line_index(offset)?;

  let (line, col) = line_index.one_based().raw();
  println!("The offset is on line {line}, column {col}.");
}
Commit count: 0

cargo fmt