chars_input

Crates.iochars_input
lib.rschars_input
version0.2.2
sourcesrc
created_at2017-12-14 19:50:02.91323
updated_at2018-01-28 00:48:20.257582
descriptionchars input
homepagehttps://gitlab.com/nathanfaucett/rs-chars_input
repositoryhttps://gitlab.com/nathanfaucett/rs-chars_input.git
max_upload_size
id43120
size15,191
Nathan Faucett (nathanfaucett)

documentation

README

chars_input

chars input

extern crate chars_input;


use chars_input::{Chars, Input, State};


fn line_count(input: &mut Input, state: &mut State) -> usize {
    let mut lines = 0;

    while let Some(_) = input.read_line(state) {
        lines += 1;
    }

    lines
}


fn main() {
    let mut lines = Chars::new("Hello, world!\n some chars input.\n".chars());
    assert_eq!(line_count(&mut lines, &mut State::new()), 2);

    let mut state = State::new();
    let mut chars = "abcdef".chars().collect::<Vec<char>>();

    assert_eq!(chars.peek(&state, 0), Some('a'));
    assert_eq!(chars.peek(&state, 1), Some('b'));
    assert_eq!(chars.peek(&state, 2), Some('c'));

    chars.read_offset(&mut state, 3);

    assert_eq!(chars.read(&mut state), Some('d'));
    assert_eq!(chars.read(&mut state), Some('e'));
    assert_eq!(chars.read(&mut state), Some('f'));

    assert_eq!(state.index(), 6);
    assert_eq!(state.row(), 1);
    assert_eq!(state.col(), 6);

    assert_eq!(chars.is_done(&state), true);
}
Commit count: 8

cargo fmt