zoozle 0.1.7

Some I/O macros like C++ cin/cout.
Documentation
pub trait Slicer{
    fn slice_before(&self,key:char)->String;
}

impl Slicer for String{
    fn slice_before(&self,key:char)->Self{
        let mut buf=String::new();
        for run in self.chars(){
            if run == key{
                return buf;
            }else{
                buf.push(run);
            }
        }
        return self.clone();
    }
}

impl Slicer for &str{
    fn slice_before(&self,key:char)->String{
        let mut buf=String::new();
        for run in self.chars(){
            if run == key{
                return buf;
            }else{
                buf.push(run);
            }
        }
        return String::from(*self);
    }
}




#[allow(dead_code)]
/// Returns Some(maximum value).
/// If vector is empty, this function returns None.
pub fn vec_max<T: std::cmp::PartialOrd + Clone>(data: &Vec<T>) -> Option<T> {
    if data.is_empty() {
        None
    } else {
        let mut max = data[0].clone();
        for run in data {
            if *run > max {
                max = run.clone();
            }
        }
        Some(max)
    }
}

#[allow(dead_code)]
/// Returns Some(minimum value).
/// If vector is empty, this function returns None.
pub fn vec_min<T: std::cmp::PartialOrd + Clone>(data: &Vec<T>) -> Option<T> {
    if data.is_empty() {
        None
    } else {
        let mut min = data[0].clone();
        for run in data {
            if *run < min {
                min = run.clone();
            }
        }
        Some(min)
    }
}


#[allow(dead_code)]
pub fn max_index<T: std::cmp::PartialOrd + Clone>(data:&Vec<T>)->Option<usize>{
    if data.is_empty(){
        None
    }else{
        let mut max = data[0].clone();
        let mut count=0;
        let mut index=0;
        for run in data {
            if *run > max {
                max = run.clone();
                index=count;
            }
            count+=1;
        }
        Some(index)
    }
}

#[allow(dead_code)]
pub fn min_index<T: std::cmp::PartialOrd + Clone>(data:&Vec<T>)->Option<usize>{
    if data.is_empty(){
        None
    }else{
        let mut min = data[0].clone();
        let mut count=0;
        let mut index=0;
        for run in data {
            if *run <min {
                min = run.clone();
                index=count;
            }
            count+=1;
        }
        Some(index)
    }
}