Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
29
third-party/vendor/generator/examples/pipe.rs
vendored
Normal file
29
third-party/vendor/generator/examples/pipe.rs
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use generator::*;
|
||||
|
||||
fn main() {
|
||||
// fn square<'a, T: Iterator<Item = u32> + 'a>(input: T) -> impl Iterator<Item = u32> + 'a {
|
||||
fn square<'a, T: Iterator<Item = u32> + Send + 'a>(input: T) -> Generator<'a, (), u32> {
|
||||
Gn::new_scoped(|mut s| {
|
||||
for i in input {
|
||||
s.yield_with(i * i);
|
||||
}
|
||||
done!();
|
||||
})
|
||||
}
|
||||
|
||||
// fn sum<'a, T: Iterator<Item = u32> + 'a>(input: T) -> impl Iterator<Item = u32> + 'a {
|
||||
fn sum<'a, T: Iterator<Item = u32> + Send + 'a>(input: T) -> Generator<'a, (), u32> {
|
||||
Gn::new_scoped(|mut s| {
|
||||
let mut acc = 0;
|
||||
for i in input {
|
||||
acc += i;
|
||||
s.yield_with(acc);
|
||||
}
|
||||
done!();
|
||||
})
|
||||
}
|
||||
|
||||
for (i, sum) in sum(square(0..20)).enumerate() {
|
||||
println!("square_sum_{i:<2} = {sum:^4}");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue