async fn file_to_records(
        file_record_options: &Option<FileRecord>,
    ) -> Result<RecordTuples, CliError> {
        let mut records: RecordTuples = vec![];

        match file_record_options {
            Some(file_record) => {
                match file_record {
                    // lines as records
                    FileRecord::Lines(lines2rec_path) => {
                        let f = File::open(lines2rec_path).await?;
                        let mut lines = BufReader::new(f).lines();
                        // reach each line and convert to byte array
                        for line in lines.next().await {
                            if let Ok(text) = line {
                                records.push((text.clone(), text.as_bytes().to_vec()));
                            }
                        }
                    }

                    // files as records
                    FileRecord::Files(files_to_rec_path) => {
                        for file_path in files_to_rec_path {
                            let file_name = file_path.to_str().unwrap_or("?");
                            let mut f = File::open(file_path).await?;
                            let mut buffer = Vec::new();

                            // read the whole file in a byte array
                            f.read_to_end(&mut buffer).await?;
                            records.push((file_name.to_owned(), buffer));
                        }
                    }
                }
            }
            None => {}
        }

        Ok(records)
    }
/// Retrieve one or more files and converts them into a list of (name, record) touples
Retrieve one or more files and converts them into a list of (name, record) touples
Retrieve one or more files and converts them into a list of ( name record ) touples
async fn file_to_records(
        file_record_options: &Option<FileRecord>,
    ) -> Result<RecordTuples, CliError> {
        let mut records: RecordTuples = vec![];
        match file_record_options {
            Some(file_record) => {
                match file_record {
                    // lines as records
                    FileRecord::Lines(lines2rec_path) => {
                        let f = File::open(lines2rec_path).await?;
                        let mut lines = BufReader::new(f).lines();
                        // reach each line and convert to byte array
                        for line in lines.next().await {
                            if let Ok(text) = line {
                                records.push((text.clone(), text.as_bytes().to_vec()));
                            }
                        }
                    }
                    // files as records
                    FileRecord::Files(files_to_rec_path) => {
                        for file_path in files_to_rec_path {
                            let file_name = file_path.to_str().unwrap_or("?");
                            let mut f = File::open(file_path).await?;
                            let mut buffer = Vec::new();
                            // read the whole file in a byte array
                            f.read_to_end(&mut buffer).await?;
                            records.push((file_name.to_owned(), buffer));
                        }
                    }
                }
            }
            None => {}
        }
        Ok(records)
    }
async fn file_to_records ( file_record_options : & Option < FileRecord > , ) -> Result < RecordTuples , CliError > { let mut records : RecordTuples = vec ! [ ] ; match file_record_options { Some ( file_record ) => { match file_record { // lines as records FileRecord :: Lines ( lines2rec_path ) => { let f = File :: open ( lines2rec_path ) . await ? ; let mut lines = BufReader :: new ( f ) . lines ( ) ; // reach each line and convert to byte array for line in lines . next ( ) . await { if let Ok ( text ) = line { records . push ( ( text . clone ( ) , text . as_bytes ( ) . to_vec ( ) ) ) ; } } } // files as records FileRecord :: Files ( files_to_rec_path ) => { for file_path in files_to_rec_path { let file_name = file_path . to_str ( ) . unwrap_or ( " " ) ; let mut f = File :: open ( file_path ) . await ? ; let mut buffer = Vec :: new ( ) ; // read the whole file in a byte array f . read_to_end ( & mut buffer ) . await ? ; records . push ( ( file_name . to_owned ( ) , buffer ) ) ; } } } } None => { } } Ok ( records ) }
Retrieve one or more files and converts them into a list of (name, record) touples
Retrieve one or more files and converts them into a list of ( name record ) touples
file_record_options
&Option<FileRecord>
file_record_options
&Option<FileRecord>