上一页 1 2 3 4 5 6 ··· 14 下一页
摘要: 创建Mutex实例 use std::sync::Mutex; fn main() { let m = Mutex::new(5); println!("m = {:?}", m); } m = Mutex { data: 5, poisoned: false, .. } 访问数据 get_mut 阅读全文
posted @ 2026-04-14 21:58 lxd670 阅读(16) 评论(0) 推荐(0)
摘要: hashset说明 天然去除重复元素 创建和初始化 new use std::collections::HashSet; fn main() { let mut set = HashSet::new(); } 查看容量和长度 use std::collections::HashSet; fn mai 阅读全文
posted @ 2026-04-14 02:09 lxd670 阅读(5) 评论(0) 推荐(0)
摘要: hashmap hashmap是一个无序的字典 创建hashmap new 创建空的hashmap use std::collections::HashMap; fn main() { // let mut map = HashMap::<String, i32>::new(); let mut m 阅读全文
posted @ 2026-04-14 02:09 lxd670 阅读(8) 评论(0) 推荐(0)
摘要: Cursor Cursor把内存数据 &[u8] → 变成可读写、可seek的虚拟文件(模拟文件、网络读写) new 创建一个新的游标来包装所提供的底层内存缓冲区 use std::io::Cursor; fn main() { // 1. 从 Vec<u8> 创建 let cursor1 = Cu 阅读全文
posted @ 2026-04-14 02:08 lxd670 阅读(8) 评论(0) 推荐(0)
摘要: std::time 只做时间戳、不做年月日。由第三方库(chrono)做 核心原因:日期太复杂,标准库不敢随便背锅 Duration 设置时间长度(间隔),通常用来延时等待、时间计算 new生成 new(秒, 纳秒) use std::time::{SystemTime, Duration}; fn 阅读全文
posted @ 2026-04-09 23:37 lxd670 阅读(12) 评论(0) 推荐(0)
摘要: Command 1.基础用法 执行命令,返回结果 use std::process::Command; fn main() { let mut cmd = Command::new("rustc"); cmd.arg("--version"); let output = cmd.output().e 阅读全文
posted @ 2026-03-16 23:33 lxd670 阅读(26) 评论(0) 推荐(0)
摘要: 官方文档 注意rand从0.10.0开始是把use rand::Rng替换为了use rand::RngExt 以下案例可以使用rand的0.9.0 数字 随机数字 use rand::Rng; fn main() { let mut rng = rand::rng(); // 随机数 let a: 阅读全文
posted @ 2026-03-05 22:49 lxd670 阅读(74) 评论(0) 推荐(0)
摘要: for循环 说明 for循环会消耗所有权 场景 行为 所有权 for item in collection 调用 .into_iter() 转移所有权(move) for item in &collection 调用 .iter() 不可变借用(&T) for item in &mut collec 阅读全文
posted @ 2026-01-30 11:20 lxd670 阅读(14) 评论(0) 推荐(0)
摘要: 条件判断 if判断 rust不会隐式的将数值转换布尔值 单分支if fn main() { let score = 85; if score >= 60 { println!("及格"); } } if加else fn main() { let score = 45; if score >= 60 阅读全文
posted @ 2026-01-30 00:46 lxd670 阅读(10) 评论(0) 推荐(0)
摘要: 提高模糊查询 提高前后模糊,SELECT * FROM population WHERE name LIKE '%三%'; 开启pg_trgm扩展 CREATE EXTENSION IF NOT EXISTS pg_trgm; 是否开启扩展 postgres=# \dx List of instal 阅读全文
posted @ 2025-11-14 14:11 lxd670 阅读(46) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 ··· 14 下一页