随笔分类 -  Rust

上一页 1 2 3 4 5 6 ··· 13 下一页
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 into_boxed_bytes fn main() { let name = "JiangBo"; println!("{:?}", name.to_owned().into_boxed_str().into_boxed_byte 阅读全文
posted @ 2022-05-29 07:49 jiangbo4444 阅读(54) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 strip_suffix fn main() { let name = "\nJiang\nBo\n"; println!("{:?}", name.strip_suffix('\n')); } parse fn main() { 阅读全文
posted @ 2022-05-29 07:47 jiangbo4444 阅读(52) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 match_indices fn main() { let name = "\nJiang\nBo\n"; name.match_indices(char::is_alphabetic) .for_each(|e| println! 阅读全文
posted @ 2022-05-29 07:45 jiangbo4444 阅读(57) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 rsplit fn main() { let name = "Jiang\nBo"; name.rsplit('\n').for_each(|e| println!("{e:?}")); } split_terminator fn 阅读全文
posted @ 2022-05-29 07:42 jiangbo4444 阅读(105) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 lines fn main() { let name = "Jiang\nBo"; name.lines().for_each(|e| println!("{e:?}")); } encode_utf16 fn main() { l 阅读全文
posted @ 2022-05-29 07:39 jiangbo4444 阅读(42) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 get_unchecked fn main() { let name = "JiangBo"; println!("{:?}", unsafe { name.get_unchecked(5..) }); } get_unchecke 阅读全文
posted @ 2022-05-29 07:35 jiangbo4444 阅读(72) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 len fn main() { let name = "JiangBo"; println!("{:?}", name.len()); } is_empty fn main() { let name = "JiangBo"; pri 阅读全文
posted @ 2022-05-29 07:33 jiangbo4444 阅读(76) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 drain fn main() { let mut name = String::from("JiangBo"); let name = name.drain(..5); println!("{:?}", name); } repl 阅读全文
posted @ 2022-05-29 07:31 jiangbo4444 阅读(41) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 remove fn main() { let mut name = String::from("JiangBo"); name.remove(4); println!("{name:?}"); } retain fn main() 阅读全文
posted @ 2022-05-29 07:29 jiangbo4444 阅读(29) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 capacity fn main() { let name = String::from("JiangBo"); println!("{:?}", name.capacity()); } reserve fn main() { le 阅读全文
posted @ 2022-05-29 07:27 jiangbo4444 阅读(32) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 new fn main() { let s = String::new(); println!("{:?}", s.capacity()); } with_capacity fn main() { let s = String::w 阅读全文
posted @ 2022-05-29 07:24 jiangbo4444 阅读(74) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-25 Rust 1.59.0 示例 or fn main() { let result: Result<u32, u32> = Ok(44); println!("{:?}", result.or(Err(4))); } or_else fn main() { let 阅读全文
posted @ 2022-05-28 13:45 jiangbo4444 阅读(41) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-25 Rust 1.59.0 示例 as_deref fn main() { let result: Result<String, u32> = Ok("ok".to_owned()); let result: Result<&str, &u32> = result. 阅读全文
posted @ 2022-05-28 13:44 jiangbo4444 阅读(35) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-24 Rust 1.59.0 示例 is_ok fn main() { let result: Result<i32, &str> = Ok(44); println!("{:?}", result.is_ok()); } is_err fn main() { let 阅读全文
posted @ 2022-05-28 13:42 jiangbo4444 阅读(47) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-23 Rust 1.59.0 示例 find_map fn main() { let vec = ["lol", "NaN", "2", "5"]; let result: Option<i32> = vec.iter().find_map(|s| s.parse() 阅读全文
posted @ 2022-05-28 13:38 jiangbo4444 阅读(50) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-23 Rust 1.59.0 示例 collect fn main() { let vec = vec![0, 1, 2, 3, 4]; let doubled: Vec<_> = vec.iter().map(|e| e * 2).collect(); for el 阅读全文
posted @ 2022-05-28 13:00 jiangbo4444 阅读(76) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-22 Rust 1.59.0 示例 take_while 在找到返回 false 的值后,忽略剩余所有元素。 fn main() { let vec = vec![0, 1, 2, 3, 4]; vec.iter() .take_while(|&e| e % 2 == 阅读全文
posted @ 2022-05-28 12:58 jiangbo4444 阅读(125) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-22 Rust 1.59.0 示例 for_each 和 for 循环类型,遍历每个元素。 fn main() { let vec = vec![0, 1, 2, 3, 4]; vec.iter().for_each(|e| println!("{e}")); } m 阅读全文
posted @ 2022-05-28 12:57 jiangbo4444 阅读(197) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-22 Rust 1.59.0 示例 iter 生成一个迭代器,可变版本 iter_mut,所有权版本 into_iter。 fn main() { let vec = vec![0, 1, 2, 3, 4]; let iter = vec.iter(); printl 阅读全文
posted @ 2022-05-28 12:55 jiangbo4444 阅读(121) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-03-17 Rust 1.59.0 概念 动态数组分配在栈上,长度可以变化。 示例 leak fn main() { let vec = vec![0, 1, 2, 3, 4]; let leak = vec.leak(); println!("{leak:?}"); } 阅读全文
posted @ 2022-05-27 19:28 jiangbo4444 阅读(126) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 ··· 13 下一页