1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::io::BufRead;

use input::{Readable, Source};

pub enum Usize1 {}
pub enum Isize1 {}
pub enum Chars {}
pub enum Bytes {}

impl Readable for Usize1 {
    type Output = usize;
    fn read<R: BufRead, S: Source<R>>(source: &mut S) -> usize {
        usize::read(source).checked_sub(1).unwrap()
    }
}

impl Readable for Isize1 {
    type Output = isize;
    fn read<R: BufRead, S: Source<R>>(source: &mut S) -> isize {
        isize::read(source).checked_sub(1).unwrap()
    }
}

impl Readable for Chars {
    type Output = Vec<char>;
    fn read<R: BufRead, S: Source<R>>(source: &mut S) -> Vec<char> {
        source.next_token_unwrap().chars().collect()
    }
}

impl Readable for Bytes {
    type Output = Vec<u8>;
    fn read<R: BufRead, S: Source<R>>(source: &mut S) -> Vec<u8> {
        source.next_token_unwrap().bytes().collect()
    }
}

#[test]
fn sanity_check() {
    use input::{scan, AutoSource};

    let src = AutoSource::from("10 20 3 chars bytes");
    scan! {
        from src,
        (l, r): (Usize1, usize),
        y: Isize1,
        c: Chars,
        b: Bytes,
    }

    assert_eq!(l..r, 9..20);
    assert_eq!(y, 2);
    assert!("chars".chars().eq(c));
    assert!("bytes".bytes().eq(b));
}