Is it possible to populate a large set at compile time?

后端 未结 3 665
-上瘾入骨i
-上瘾入骨i 2020-12-20 19:56

We have a \'delete all my data\' feature. I\'d like to delete a set of IPs from many many web log files.

Currently at runtime I open a CSV with the IP addresses to d

3条回答
  •  不思量自难忘°
    2020-12-20 20:11

    have only a single static binary to deploy

    Inline your entire CSV file using include! or include_str! and then go about the rest of your program as usual.

    use csv; // 1.0.5
    
    static CSV_FILE: &[u8] = include_bytes!("/etc/hosts");
    
    fn main() -> Result<(), Box> {
        let mut rdr = csv::ReaderBuilder::new()
            .delimiter(b'\t')
            .from_reader(CSV_FILE);
    
        for result in rdr.records() {
            let record = result?;
            println!("{:?}", record);
        }
    
        Ok(())
    }
    

    See also:

    • Is there a good way to include external resource data into Rust source code?

提交回复
热议问题