摘要: #[derive(Debug)] enum Unit{ INT(i32), STR(String), FLOAT(f32) } #[derive(Debug)] struct People{ name: String, elements: Vec<Unit> } impl IntoIterator 阅读全文
posted @ 2022-07-28 13:36 CrossPython 阅读(27) 评论(0) 推荐(0)
摘要: struct CountdownIterator(i32); impl Iterator for CountdownIterator { type Item = i32; fn next(&mut self) -> Option<Self::Item> { self.0 -= 1; if self. 阅读全文
posted @ 2022-07-28 12:26 CrossPython 阅读(23) 评论(0) 推荐(0)
摘要: use std::ptr; use std::fmt::{ Display, Formatter, Result }; pub struct Node { value: i32, next: *mut Node } impl Node { pub fn new(val: i32) -> Self { 阅读全文
posted @ 2022-07-28 11:52 CrossPython 阅读(27) 评论(0) 推荐(0)
摘要: 通过迭代器提供的filter()和collect()方法。 let list2: Vec<_> = (1..=100).filter(|i| i%3 == 0).collect();assert_eq!(list1, list2); take(k)取前面k个元素。 迭代器调用take()后,迭代器的 阅读全文
posted @ 2022-07-28 10:39 CrossPython 阅读(61) 评论(0) 推荐(0)