read_chars 0.3.0

An iterator over characters read from some I/O source.
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented0 out of 2 items with examples
  • Size
  • Source code size: 5.23 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 446.56 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • AshtonSnapp/read_chars
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • AshtonSnapp

read_chars

This is just a simple library I made for use in a new lexer for my programming language project Rouge. You are free to use it how you wish under the MIT license.

use read_chars::ReadChars;
use std::convert::From;
use std::io;
use std::fs::File;

fn main() -> io::Result<()> {
	let chars = ReadChars::from(File::open("test.txt")?);

	let max_nesting = chars.filter(|r| match r { Ok(c) if c == '(' || c == ')' => Some(c), _ => None })
		.scan(0, |acc, chr| if chr == '(' { acc + 1 } else { acc - 1 })
		.max()
		.ok_or_else(|| io::Error::from(io::ErrorKind::InvalidData))?;

	println!("Max parentheses nesting in file 'text,txt' is {max_nesting}.");

	Ok(())
}