rusty_cc/
lib.rs

1#![allow(dead_code)]
2mod reading;
3pub use reading::Reading;
4mod utils;
5use std::fmt::Arguments;
6use std::io::{stdin, stdout, BufWriter, Stdout, Write};
7pub use utils::*;
8
9pub mod prelude {
10    pub use super::{Reading, RW};
11    pub use std::cmp::{max, min};
12}
13
14pub struct RW(BufWriter<Stdout>);
15
16impl RW {
17    pub fn new() -> Self {
18        RW(BufWriter::new(stdout()))
19    }
20
21    pub fn write_fmt<'a>(&mut self, args: Arguments<'a>) -> Result<(), ()> {
22        self.0.write_fmt(args).unwrap();
23        Ok(())
24    }
25}
26
27impl Drop for RW {
28    fn drop(&mut self) {
29        self.0.flush().unwrap();
30    }
31}
32
33impl Reading for RW {
34    fn read_line(&mut self) -> String {
35        let mut txt = String::new();
36        stdin().read_line(&mut txt).unwrap();
37        txt.trim().to_owned()
38    }
39}