zoozle 0.1.9

Some I/O macros like C++ cin/cout.
Documentation
fn _swap_func<T>(first:&mut T,second:&mut T)
   where T:Clone
{
   let temp=first.clone();
   *first=second.clone();
   *second=temp;
}

 pub fn read_string()->Option<String>{
    let mut buff=String::new();
    match std::io::stdin().read_line(&mut buff){
        Ok(_)=>{
            Some(buff)
        },
        Err(_)=>{
            None
        },
    }
 }
 
 pub fn read_into<T>() -> Option<T>
   where T:std::str::FromStr
{
   let mut s = String::new();
   std::io::stdin().read_line(&mut s).ok();
   s.trim().parse().ok()
}

pub fn safe_scan<T>(default:T) -> T
   where T:std::str::FromStr
{
   let mut buff = String::new();
   std::io::stdin().read_line(&mut buff).ok();
   buff.trim().parse().unwrap_or(default)
}

#[allow(unused_macros)]
#[macro_export]

///Print macro like C++ cout.
/// # Examples
/// let x=6;
/// echo!(x,"is my favorite number.")
macro_rules! echo {
   ($($e:ident),*) => {
       $(
           (print!("{}", $e));
       )*
       print!("\n");
   };
  
   ($($e:expr),*) => {
       $(
           (print!("{}", $e));
       )*
       print!("\n");
   };      
}

#[allow(unused_macros)]
///Scan macro like C++ cin.
/// Ignores whitespace.
/// # Examples
/// let x:i32;
/// let y=String::new();
/// scan!(x,y);
/// # Panics
/// If failed to translate into desired type,
/// this macro calls panic!() macro.
#[macro_export]
macro_rules! scan {
   ($($e:expr),*) => {
       $(
           ($e=zoozle::io::read_into().unwrap());
       )*
   };
   ($($e:ident),*) => {
    $(
        ($e=zoozle::io::read_into().unwrap());
    )*
};     
}

#[allow(unused_macros)]
#[macro_export]
///Scan macro like C++ cin.
/// Divided by whitespace.
/// # Examples
/// let x:i32;
/// let y=String::new();
/// space_scan!(x,y);   /// foo bar
/// # Panics
/// If failed to translate into desired type,
/// this macro calls panic!() macro.
macro_rules!  space_scan {
   ($($e:expr),*) => {
       let mut temp=String::new();
       std::io::stdin().read_line(&mut temp);
       let tempvec:Vec<&str>=temp.split_whitespace().collect();
       let mut count=0;
       $(
           $e=tempvec[count].parse().unwrap();
           count+=1;
       )*
   };
}

///Scan macro like C++ cin.
/// Ignores whitespace.
/// Never call panic!().
/// If failed to translate into desired type,
/// the default value will be assigned.
/// # Examples
/// let x:i32; 
/// x=safe_scan!(9999);
#[allow(unused_macros)]
#[macro_export]
macro_rules!  safe_scan {
    /*($e:expr) => {
        zoozle::io::safe_scan($e)
    };*/
      
    ($e:ident) => {
        zoozle::io::safe_scan($e)
    }  
 }

#[allow(unused_macros)]
#[macro_export]
///Simple swap macro.
///You don't need &mut before variable.
macro_rules!  swap {
    ($e:ident,$m:ident) => {
        zoozle::io::_swap_func(&mut $e,&mut $m);
    }  
}