Struct strizer::StreamTokenizer[][src]

pub struct StreamTokenizer<'a, R> { /* fields omitted */ }

StreamTokenizer<R> defines the structure for the tokenization of a given input that implements the BufRead trait. By using BufRead, the content of the text data is efficiently tokenized by reading it line-by-line.

Examples

use std::fs::File;
use std::io::BufReader;
use strizer::{StreamTokenizer, Token, TokenKind};

fn main() -> std::io::Result<()> {
  let file = File::open("log.txt")?;
  let mut reader = BufReader::new(file);

  let error_count = StreamTokenizer::new(&mut reader, &[])
    .filter(|(_, _, slice)| slice == "ERROR")
    .count();

  println!("number of error logs: {}", error_count);
  Ok(())
}

Implementations

impl<'a, R: BufRead> StreamTokenizer<'a, R>[src]

pub fn new(input: &'a mut R, identifiers: &'a [char]) -> Self[src]

Creates a new StreamTokenizer<R> with a given BufRead input. The different offsets and data used while iterating are initialized. An array of identifiers is passed by, and the associated characters will be identified as Character Token during the tokenization.

Examples

use std::io::Cursor;
use strizer::{StreamTokenizer, Token, TokenKind};

let cursor = &mut Cursor::new("abracadabra");
let tokenizer = StreamTokenizer::new(cursor, &['a']);

let a_count = tokenizer
  .filter(|(token, _, slice)| token.is_character() && slice == "a")
  .count();

assert_eq!(a_count, 5);

Trait Implementations

impl<'a, R: Debug> Debug for StreamTokenizer<'a, R>[src]

impl<'a, R: BufRead> Iterator for StreamTokenizer<'a, R>[src]

StreamTokenizer<R> implementation for Iterator.

type Item = (Token, Span, String)

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a, R> RefUnwindSafe for StreamTokenizer<'a, R> where
    R: RefUnwindSafe

impl<'a, R> Send for StreamTokenizer<'a, R> where
    R: Send

impl<'a, R> Sync for StreamTokenizer<'a, R> where
    R: Sync

impl<'a, R> Unpin for StreamTokenizer<'a, R>

impl<'a, R> !UnwindSafe for StreamTokenizer<'a, R>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.