zoozle 0.1.0

Some I/O macros like C++ cout/cin.
Documentation
#[allow(unused_macros)]
#[macro_export]

///Print macro like C++ cout.
/// # Examples
/// let x=6;
/// echo!(6,"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::oft::read_into());
       )*
   };     
}
 
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]
///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::oft::safe_scan_func($e)
    };
      
    ($e:ident) => {
        zoozle::oft::safe_scan_func($e)
    }  
 }

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

pub fn swap_func<T>(first:&mut T,second:&mut T)
   where T:Clone
{
   let temp=first.clone();
   *first=second.clone();
   *second=temp;
}

 
pub fn safe_scan_func<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)
 }
 


pub fn goutln<T:std::fmt::Debug>(target:T){
    println!("{:?}",target);
 }
  
 pub fn gout<T:std::fmt::Debug>(target:T){
    print!("{:?}",target);
 }
  
 pub fn read_to_str()->String{
    let mut buff=String::new();
    match std::io::stdin().read_line(&mut buff){
        Ok(_content)=>{
            buff
        },
        Err(_no)=>{
            "Failed".to_string()
        },
    }
 }
 
 pub fn read_into<T>() -> T
   where T:std::str::FromStr
{
   let mut s = String::new();
   std::io::stdin().read_line(&mut s).ok();
   s.trim().parse().ok().unwrap()
}