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

相关推荐
咚咚锵咚咚锵20 小时前
DrissionPage的学习
前端·python·学习
huabuyu20 小时前
将 Markdown 转为 AST:实现思路与实战解析
前端
前端Hardy20 小时前
惊艳同事的 Canvas 事件流程图,这篇教会你
前端·javascript·css
WAWA战士20 小时前
mysql总结
数据库
哔哩哔哩技术20 小时前
KMP on iOS 深度工程化:模块化、并发编译与 98% 增量构建加速
前端
熊思宇20 小时前
Sqlite“无法加载 DLL“e_sqlite3”: 找不到指定的模块”解决方法
数据库·sqlite
往事随风去20 小时前
面试官:mysql从数据库断开一段时间后,部分binlog已丢失,如何重建主从?
运维·数据库·mysql
神仙别闹20 小时前
基于 Vue+SQLite3开发吉他谱推荐网站
前端·vue.js·sqlite
Async Cipher20 小时前
CSS 居中
前端·css·css3
J.Kuchiki20 小时前
【PostgreSQL内核学习 —— (SeqScan算子)】
数据库·postgresql