prime-iter

A somewhat optimized incremental-sieve based prime generator.

Examples

The interface is given in the form of an iterator, so usage is very simple and idiomatic: ```rust let fiftysecondprime = prime_iter::primes::().nth(51).unwrap();

asserteq!(fiftysecondprime, 239); rust let primesum: i32 = prime_iter::primes::().take(100).sum();

asserteq!(primesum, 24133); rust let twodigitprimes: Vec = primeiter::primes::().skipwhile(|&x| x < 10).take_while(|&x| x < 100).collect();

asserteq!(twodigitprimes, [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]); And of course `for` loops work too: rust for prime in primeiter::primes::() { if prime % 10 == 1 { println!("{prime}"); } } ```

no_std Support

prime-iter supports no-std environments, however it does use allocations. Disable the std feature, which is enabled by default, for a no_std environment.

Installation

Either add this line to your Cargo.toml: toml prime-iter = "0.1" Or simply run cargo add prime-iter.

License

Licensed under either of:

at your option.