6 个版本
使用旧的 Rust 2015
0.2.2 | 2018 年 1 月 28 日 |
---|---|
0.2.1 | 2018 年 1 月 8 日 |
0.1.2 | 2017 年 12 月 20 日 |
#253 在 解析器工具
23 每月下载次数
14KB
451 行
chars_input
chars 输入
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);
}