Make great things

What I cannot create, I do not understand.

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

01 2021 档案

摘要:原文链接 https://edgarluque.com/blog/wrapping-errors-in-rust 当我在开发 paypal-rs 库时, 注意到了错误处理不是很好. 在这个库中, 我需要处理 2 中不同类型的错误: HTTP 相关错误, reqwest::Error Paypal A 阅读全文
posted @ 2021-01-28 23:11 wbin91 阅读(456) 评论(0) 推荐(0)

摘要:最近在刷 Leetcode, 每日题打卡题经常出现并查集, 这里记录下使用 Rust 实现的并查集. pub struct UnionFind { n: usize, fa: Vec<usize>, } impl UnionFind { pub fn new(n: usize) -> Self { 阅读全文
posted @ 2021-01-28 22:00 wbin91 阅读(250) 评论(0) 推荐(0)

摘要:原文地址 https://leshow.github.io/post/cheat_rank_n/ 假设你有一个 enum 类描述一组可能的分支, 有一些函数需要对可能的分支进行处理, 而对每个分支存在一个对应的类型, 比如 enum Var { One, Two, } #[derive(Serial 阅读全文
posted @ 2021-01-28 13:51 wbin91 阅读(306) 评论(0) 推荐(0)

摘要:Cell: 可以改变值, 不需要 mut 修饰 (inherited mutability). let x = Cell:new(100); x.set(10); 有些时候必须要使用 interior mutability, 比如 Rc::Clone 时修改引用计数. RefCell: 运行时 bo 阅读全文
posted @ 2021-01-18 15:13 wbin91 阅读(90) 评论(0) 推荐(0)

摘要:迭代器作为输入 以下代码 fn func1(data: &[u32]) {} 如果我们只需要迭代 data 中的数据, 那么可以将参数改写成 IntoIterator 使该函数更通用: fn func1(data: impl IntoIterator<Item=u32>) {} 构造和扩展集合 如果 阅读全文
posted @ 2021-01-14 15:04 wbin91 阅读(261) 评论(0) 推荐(0)

摘要:rust - What is the meaning of 'static as a function constraint? - Stack Overflow fn foo<F: T + 'static>(f: F) {} 在类型约束中的生命周期泛型表示该类型的所有生命周期泛型参数都必须满足生命周 阅读全文
posted @ 2021-01-07 10:50 wbin91 阅读(3097) 评论(0) 推荐(0)