>>929 メソッド定義と残り
#![feature(coroutines, coroutine_trait, yield_expr)]

use std::ops::{Coroutine, CoroutineState};
use std::pin::Pin;

// due to orphan rule
trait CoroutineExt: Coroutine<(), Return = ()> + Unpin + Sized {
fn into_iter(mut self) -> impl Iterator<Item = Self::Yield> {
std::iter::from_fn(move || self.next())
}
fn next(&mut self) -> Option<Self::Yield> {
match Pin::new(self).resume(()) {
CoroutineState::Yielded(n) => Some(n),
_ => None,
}
}
}
impl<C: Coroutine<(), Return = ()> + Unpin + Sized> CoroutineExt for C {}

fn main() {
let n = std::env::args_os()
.nth(1)
.and_then(|s| s.into_string().ok())
.and_then(|s| s.parse().ok())
.unwrap_or(100);

for prime in prime_generator().into_iter().take(n) {
print!("{prime} ");
}
println!();
}