library-rs

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub naoya675/library-rs

:heavy_check_mark: macro/query/src/lib.rs

Verified with

Code

#[macro_export]
macro_rules! define_query {
    (
        $name:ident {
            $( $tag:literal => $variant:ident ( $( $field:ident : $ty:ty ),* $(,)? ) ),* $(,)?
        }
    ) => {
        #[derive(Copy, Clone, Debug, Eq, PartialEq)]
        enum $name {
            $( $variant( $( $ty ),* ), )*
        }
        use $name::*;

        impl proconio::source::Readable for $name {
            type Output = $name;
            fn read<R: std::io::BufRead, S: proconio::source::Source<R>>(source: &mut S) -> Self::Output {
                match u32::read(source) {
                    $(
                        $tag => {
                            input! { from source, $( mut $field: $ty ),* }
                            $variant( $( $field ),* )
                        }
                    )*
                    _ => unreachable!(),
                }
            }
        }
    }
}
Back to top page