-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInto_Iterators.rs
More file actions
53 lines (42 loc) · 1002 Bytes
/
Into_Iterators.rs
File metadata and controls
53 lines (42 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Into Iterators
*/
// IntoIterator {
// type Item;
// type IntoIter;
// fn into_iter(self) -> Self::IntoIter{
// }
// }
struct Book{
name:String,
author:String,
genere:String,
}
// struct BookIter{
// properties: Vec<String>,
// }
// impl Iterator for BookIter{
// type Item = String;
// fn next(&mut self) -> Option<Self::Item>{
// self.properties.pop()
// }
// }
impl IntoIterator for Book{
type Item= String;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter{
vec![self.name, self.author, self.genere].into_iter()
}
}
fn main(){
let b1: Book = Book{
name:"RamLal Stories".to_string(),
author:"RamLal".to_string(),
genere:"Horror".to_string(),
};
let mut bookiter = b1.into_iter();
println!("{:?}", bookiter.next());
println!("{:?}", bookiter.next());
println!("{:?}", bookiter.next());
println!("{:?}", bookiter.next());
}