You can make your own structs Readable using the #[derive_readable] attribute (requires the derive feature). This allows you to use your custom types directly inside input! or read_value! macros.
When using #[derive_readable], types used in the struct fields are automatically translated to their actual output types. For example, if a field is declared as proconio::marker::Usize1, the resulting struct field will be of type usize.
Example
#[cfg(feature = "derive")]
{
use proconio::input;
use proconio::derive_readable;
use proconio::marker::Usize1;
#[derive_readable]
struct Weight;
#[derive_readable]
struct Cost(i32);
#[derive_readable]
struct Edge {
from: usize,
to: Usize1, // The real Edge::to has type usize.
weight: Weight,
cost: Cost,
}
fn main() {
input! {
edge: Edge,
}
}
}
#[cfg(feature = "derive")]
{
extern crate proconio;
use proconio::input;
use proconio::source::auto::AutoSource;
use proconio::derive_readable;
#[derive_readable]
#[derive(PartialEq, Debug)]
struct Weight;
#[derive_readable]
#[derive(PartialEq, Debug)]
struct Cost(i32);
#[derive_readable]
#[derive(Debug)]
struct Edge {
from: usize,
to: proconio::marker::Usize1, // The real Edge::to has type usize.
weight: Weight,
cost: Cost,
}
fn main() {
# let source = AutoSource::from("12 32 35");
input! {
# from source,
edge: Edge,
}
# assert_eq!(edge.from, 12);
# assert_eq!(edge.to, 31);
# assert_eq!(edge.weight, Weight);
# assert_eq!(edge.cost, Cost(35));
}
}