reading-liner 0.1.0

A Stream reader which can convert between byte offset and line-column numbers. Support any type which implements io::Read.
Documentation
  • Coverage
  • 44.74%
    17 out of 38 items documented0 out of 30 items with examples
  • Size
  • Source code size: 21.28 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.94 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • ireina7/reading-liner
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ireina7

reading-liner

Reading and convert offset and line-column location.

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

Core methods

  • Stream::line_index(&mut self, offset:: location::Offset) -> io::Result<location::line_column::ZeroBased>

  • Stream::offset_of(&mut self, line_index: location::line_column::ZeroBased) -> io::Result<location::Offset>

  • Stream::read_line_index(&mut self, offset:: location::Offset, buf: &mut Vec<u8>) -> io::Result<location::line_column::ZeroBased>

  • Stream::read_offset_of(&mut self, line_index: location::line_column::ZeroBased, buf: &mut Vec<u8>) -> io::Result<location::Offset>

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}.");
}