Rust bin 文件比较差异

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 同时迭代 两个数组

相关推荐
一 乐1 小时前
婚纱摄影网站|基于ssm + vue婚纱摄影网站系统(源码+数据库+文档)
前端·javascript·数据库·vue.js·spring boot·后端
C_心欲无痕2 小时前
ts - tsconfig.json配置讲解
linux·前端·ubuntu·typescript·json
清沫2 小时前
Claude Skills:Agent 能力扩展的新范式
前端·ai编程
yinuo3 小时前
前端跨页面通信终极指南:方案拆解、对比分析
前端
1.14(java)3 小时前
SQL数据库操作:从CRUD到高级查询
数据库
古城小栈3 小时前
Rust 迭代器产出的引用层数——分水岭
开发语言·rust
yinuo3 小时前
前端跨页面通讯终极指南⑨:IndexedDB 用法全解析
前端
Full Stack Developme3 小时前
数据库索引的原理及类型和应用场景
数据库
xkxnq4 小时前
第二阶段:Vue 组件化开发(第 16天)
前端·javascript·vue.js
烛阴4 小时前
拒绝配置地狱!5 分钟搭建 Three.js + Parcel 完美开发环境
前端·webgl·three.js