rust
use std::collections::HashSet;
use std::fs::File;
use std::io::prelude::*;
fn main() {
let file_1 = "test.bin";
let file_2 = "test2.bin";
let mut fd_1 = File::open(file_1).expect("open file_1 error");
let mut fd_2 = File::open(file_2).expect("open file_2 error");
let mut buffer_1: Vec<u8> = Vec::new();
let mut buffer_2: Vec<u8> = Vec::new();
fd_1.read_to_end(&mut buffer_1).expect("read error from test.bin");
fd_2.read_to_end(&mut buffer_2).expect("read error from test2.bin");
let set1: HashSet<_> = buffer_1.iter().cloned().collect();
let set2: HashSet<_> = buffer_2.iter().cloned().collect();
let union: HashSet<_> = set1.union(&set2).cloned().collect();
let diff: Vec<u8> = union.into_iter().collect();
println!("diff test.bin with test2.bin: {:?}", diff);
}
有没有 python 的味道
一样的编译器,这个味道就不一样了
还不用担心内存安全的问题
这也是为什么 rust 进入内核的原因,优秀的表达能力
平替 C
Rust 同时迭代 两个数组