type LogOption = Box<dyn FnMut(&mut Writer)>;

fn WithOutType(out_type: OutType) -> LogOption {
    Box::new(move |w: &mut Writer| w.out_type = out_type)
}

fn WithLogDir(log_dir: String) -> LogOption {
    Box::new(move |w: &mut Writer| w.log_dir = log_dir.to_owned())
}
 pub fn new(options: Option<Vec<LogOption>>) -> Self {
        let nowTime = Instant::now();
        let mut w = Writer {
            out_type: OutType::OutStd,
            log_dump: false,
            std_color: false,
            zip_start: nowTime,
            zip_day: 7,
            ..Default::default()
        };
        if let Some(mut ops) = options {
            for option in ops.iter_mut() {
                option(&mut w);
            }
        }
        w
    }


    
mod tests {
    use super::*;
    #[test]
    fn test_option() {
        let mut w = Writer::new(None);
        println!("writer:{:?}", w);
        let mut options: Vec<LogOption> = Vec::new();
        options.push(WithOutType(OutType::OutFile));
        options.push(WithLogDir("haha writer".to_string()));
        let mut w2 = Writer::new(Some(options));
        println!("writer2:{:?}", w2);
    }
}