Module proconio::source [−][src]
Defines whitespace-splitted token stream wrapping actual stream like stdin.
The main is trait Source
. This is implemented to the following two type of source:
- Read entire source at once. (
once::OnceSource
) - Read source line by line. (
line::LineSource
)
OnceSource
is very fast, while LineSource
is handy for local debugging. OnceSource
must
read entire input before any other work and you must put EOF (Ctrl-D on Unix or Ctrl-Z on
Windows) after input. LineSource reads source one by one. Simply press enter to input.
There is another source named auto::AutoSource
. AutoSource
is OnceSource
in release
build, is LineSource
in debug build. If you use debug build in local testing, LineSource
,
convenience version is used. In judge server it is compiled in release mode, so OnceSource
,
faster version is used. This is usually no problem in judging (except interactive problem?).
You can specify the source to be used in input!
as follows:
use proconio::source::auto::AutoSource; use proconio::input; let source = AutoSource::from("32 54 -23"); input! { from source, n: u8, m: u32, l: i32, } println!("{} {} {}", n, m, l); assert_eq!(n, 32); assert_eq!(m, 54); assert_eq!(l, -23);
In above example, OnceSource<BufReader<&[u8]>>
and LineSource<BufReader<&[u8]>>
implements
From<&str>
, so you can create the source from a string literal. You can create an instance
directly from the value of type implementing BufRead
by using OnceSource::new()
and
LineSource::new()
.
If you use input!
macro with no source specified then it uses AutoSource
with stdin. So,
locally LineSource
are used, in the server OnceSource
are used. OnceSource
and
LineSource
behaves samely in point of the read result, but, unintentionally, it may differ in
a bare possibility. If it should differ, you can manually specify LineSource
as source
of
input!
.
Modules
auto | Defines |
line | |
once |
Traits
Readable | A trait representing which type can be read from |
Source | The main trait. Types implementing this trait can be used for source of |