chore: reorg

This commit is contained in:
2020-10-17 11:53:39 +08:00
parent 899428370b
commit af97622c79
12 changed files with 0 additions and 0 deletions

5
__std/iter/Cargo.lock generated Normal file
View File

@@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "iter"
version = "0.1.0"

9
__std/iter/Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "iter"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

77
__std/iter/src/main.rs Normal file
View File

@@ -0,0 +1,77 @@
struct Seq {
start: i32,
end: i32,
}
impl Seq {
pub fn new(start: i32, end: i32) -> Self {
Self { start, end, }
}
}
impl Iterator for Seq {
type Item = i32;
fn next(&mut self) -> Option<i32> {
if self.start < self.end {
let a = self.start;
self.start += 1;
Some(a)
} else {
None
}
}
}
fn main() {
test_001();
test_002();
test_003();
test_004();
}
// -> 10 11 12 13 14
fn test_001() {
println!("## test001");
let seq = Seq::new(10, 15);
print!("->");
for a in seq {
print!(" {}", a);
}
println!();
}
// -> 10 11 12 13 14
fn test_002() {
println!("## test002");
let mut seq = Seq::new(10, 15);
print!("->");
while let Some(a) = seq.next() {
print!(" {}", a);
}
println!();
}
// -> 10 11 12
fn test_003() {
println!("## test003");
let mut seq = Seq::new(10, 15).take(3);
print!("->");
while let Some(a) = seq.next() {
print!(" {}", a);
}
println!();
}
// -> 10
// -> 10 11 12 13 14
fn test_004() {
println!("## test004");
let mut seq = Seq::new(10, 15).peekable();
println!("-> {}", seq.peek().unwrap());
print!("->");
while let Some(a) = seq.next() {
print!(" {}", a);
}
println!();
}