随笔分类 -  rust

tokio 基础知识学习
摘要:1. 创建 tokio Runtime 直接创建: //默认的工作线程数量将和CPU核数(虚拟核,即CPU线程数)相同 let rt = tokio::runtime::Runtime::new().unwrap(); //单线程 tokio::runtime::Builder::new_curre 阅读全文

posted @ 2023-10-24 23:24 Lemo_wd 阅读(622) 评论(0) 推荐(0)

rust 基础 —— Option 的 as_ref 与 as_deref
摘要:代码: fn hello(name: &String) { println!("Name is {}", name); } fn greet(name: &str) { println!("Name is {}", name); } fn main() { let option_name: Opti 阅读全文

posted @ 2022-11-10 09:53 Lemo_wd 阅读(733) 评论(0) 推荐(0)

rust 基础 —— 创建链表
摘要:使用枚举类 use crate::List::{Cons, Nil}; enum List { // Cons:元组结构体,包含链表的一个元素和一个指向下一节点的指针 Cons(u32, Box<List>), // Nil:末结点,表明链表结束 Nil, } // 可以为 enum 定义方法 im 阅读全文

posted @ 2022-11-04 14:52 Lemo_wd 阅读(466) 评论(0) 推荐(1)

rust 基础 —— iterator 迭代器
摘要:一、自定义迭代器 实现 Iterator trait 即可 pub struct Counter { pub count: usize, } impl Iterator for Counter { type Item = usize; fn next(&mut self) -> Option<Sel 阅读全文

posted @ 2021-07-16 22:38 Lemo_wd 阅读(104) 评论(0) 推荐(0)

导航