From 071c3501dbe885d1d8a077fc60bb8e1ea120f63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20S=C3=B6rng=C3=A5rd?= <44257381+JSorngard@users.noreply.github.com> Date: Fri, 22 Nov 2024 11:15:07 +0100 Subject: [PATCH] Clearer macro docs (#83) * Update README.md * Remove less important example * Update lib.rs * Update lib.rs * Update README.md * Update lib.rs * cargo update --- Cargo.lock | 32 ++++++++++++++++---------------- README.md | 26 +++++--------------------- src/lib.rs | 28 +++++++--------------------- 3 files changed, 28 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 509ba7c..81d4439 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,18 +76,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" dependencies = [ "anstyle", "clap_lex", @@ -95,9 +95,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" [[package]] name = "const-primes" @@ -223,9 +223,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "540654e97a3f4470a492cd30ff187bc95d89557a903a2bbf112e2fae98104ef2" [[package]] name = "js-sys" @@ -238,9 +238,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.162" +version = "0.2.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" [[package]] name = "log" @@ -325,9 +325,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -522,9 +522,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.87" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -543,9 +543,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "walkdir" diff --git a/README.md b/README.md index eb67744..a14410d 100644 --- a/README.md +++ b/README.md @@ -47,20 +47,6 @@ assert!(CACHE.is_prime(1000).is_none()); assert!(CACHE.count_primes_leq(1000).is_none()); ``` -Want only the numbers? Use the `primes` function, or convert the cache into an array: - -```rust -use const_primes::{primes, Primes}; - -const CACHE: Primes<10> = Primes::new(); - -const PRIMES_ARRAY1: [u32; 10] = primes(); -const PRIMES_ARRAY2: [i32; 10] = PRIMES.into_array(); - -assert_eq!(PRIMES_ARRAY1, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]); -assert_eq!(PRIMES_ARRAY1, PRIMES_ARRAY2); -``` - ## Example: primality checking Use `is_prime` to test whether a given number is prime: @@ -75,13 +61,11 @@ assert!(CHECK); ## Example: generate the three primes after 5000000031 -The crate also provides prime generation and sieving functions that can be used -to work with ranges of large numbers that don't start at zero, e.g. -`primes_geq` and `sieve_lt`. These functions can use large sieves to compute -large primes, but don't need to return the entire sieve, just the requested numbers. -They are most conveniently used through the macros `primes_segment!` and -`sieve_segment!` that automatically compute the size of the sieve that's needed -for a certain computation. +The crate also provides prime generation and sieving functionality for computing arrays of +large prime numbers above or below some limit, without having to also include every single prime number from 2 and up in the +resulting constant, and thus potentially the binary. +This functionality is most conveniently accessed through the macros `primes_segment!` and +`sieve_segment!` that automatically compute the size of the prime sieve that is needed for a certain computation. Compute 3 primes greater than or equal to 5000000031: diff --git a/src/lib.rs b/src/lib.rs index 04414f6..0ed70f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,20 +37,6 @@ //! assert!(CACHE.prime_pi(1000).is_none()); //! ``` //! -//! Want only the numbers? Use the function [`primes`], or convert the cache into an array: -//! -//! ``` -//! use const_primes::{primes, Primes}; -//! -//! const CACHE: Primes<10> = Primes::new(); -//! -//! const PRIMES_ARRAY1: [u32; 10] = primes(); -//! const PRIMES_ARRAY2: [u32; 10] = CACHE.into_array(); -//! -//! assert_eq!(PRIMES_ARRAY1, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]); -//! assert_eq!(PRIMES_ARRAY1, PRIMES_ARRAY2); -//! ``` -//! //! # Example: primality checking //! //! Use [`is_prime`] to test whether a given number is prime: @@ -65,14 +51,14 @@ //! //! # Example: generate the three primes after 5000000031 //! -//! The crate also provides prime generation and sieving functions that can be used to work -//! with ranges of large numbers that don't start at zero, e.g. `primes_geq` and `sieve_lt`. -//! These functions can use large sieves to compute large primes, -//! but don't need to return the entire sieve, just the requested numbers. -//! They are most conveniently used through the macros `primes_segment!` and `sieve_segment!` -//! that automatically compute the size of the sieve that's needed for a certain computation. +//! The crate also provides prime generation and sieving functionality for computing arrays of large +//! prime numbers above or below some limit, without having to also include every single prime number from 2 and up in the +//! resulting constant, and thus potentially the binary. +//! This functionality is most conveniently accessed through the macros [`primes_segment!`] and +//! [`sieve_segment!`] that automatically compute the size of the prime sieve that is needed +//! for a certain computation. //! -//! Compute 3 primes greater than or equal to 5000000031: +//! Compute the three primes greater than or equal to 5000000031: //! //! ``` //! use const_primes::{primes_segment, GenerationError};