rust iter3ok.

python;gutter:true;</p> <h1>[derive(Debug)]</h1> <p>enum Unit{ INT(i32), STR(String), FLOAT(f32) }</p> <h1>[derive(Debug)]</h1> <p>struct People{ name: String, elements: Vec }</p> <p>impl IntoIterator for People { type Item = Unit; type IntoIter = std::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { self.elements.into_iter() } }</p> <p>struct Family{ name:String, peoples: Vec }</p> <p>impl IntoIterator for Family { type Item = Vec; type IntoIter = std::vec::IntoIter>; fn into_iter(self) -> Self::IntoIter {</p> <pre><code> let mut tmp_out:Vec> = vec![]; // self.peoples.into_iter() for each in self.peoples{ let mut tmp_inner :Vec= vec![]; for i in each.elements{ tmp_inner.push(i); } tmp_out.push(tmp_inner); } tmp_out.into_iter() } </code></pre> <p>}</p> <p>fn main(){ let a1 = Unit::INT(1_i32); let a2 = Unit::FLOAT(2.2_f32); let a3 = Unit::STR("abc".to_string()); let peo1 = People{ name: "Tina".to_string(), elements: vec![a1, a2] }; let peo2 = People{ name: "Bob".to_string(), elements: vec![a3] }; let f = Family{ name: "Ahome".to_string(), peoples: vec![peo1, peo2] };</p> <pre><code>for each in f{ println!("{:?}", each); } </code></pre> <pre><code> //let x:Vec // println!("{:?}", x); ;gutter:true;
}

Original: https://www.cnblogs.com/pythonClub/p/16528349.html
Author: CrossPython
Title: rust iter3ok.

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/15776/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总