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

相关推荐
牛奶8 小时前
2026年大模型怎么选?前端人实用对比
前端·人工智能·ai编程
牛奶8 小时前
前端人为什么要学AI?
前端·人工智能·ai编程
Kagol10 小时前
🎉OpenTiny NEXT-SDK 重磅发布:四步把你的前端应用变成智能应用!
前端·开源·agent
GIS之路11 小时前
ArcGIS Pro 中的 notebook 初识
前端
JavaGuide12 小时前
7 道 RAG 基础概念知识点/面试题总结
前端·后端
ssshooter12 小时前
看完就懂 useSyncExternalStore
前端·javascript·react.js
格砸13 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端
Live0000013 小时前
在鸿蒙中使用 Repeat 渲染嵌套列表,修改内层列表的一个元素,页面不会更新
前端·javascript·react native
柳杉13 小时前
使用Ai从零开发智慧水利态势感知大屏(开源)
前端·javascript·数据可视化