From f823efdafab1a2d7e0eb66894ba35402bb77adec Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 26 Sep 2022 12:48:38 -0700 Subject: [PATCH] Add prime trait --- Cargo.lock | 7 ++++++ Cargo.toml | 1 + src/ordinal.rs | 4 ++++ src/subcommand/server/templates/ordinal.rs | 28 +++++----------------- templates/ordinal.html | 1 + 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ead9f9bfc0..3d2d99a204 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2154,6 +2154,7 @@ dependencies = [ "mime_guess", "nix 0.24.2", "pretty_assertions", + "primes", "pulldown-cmark", "rayon", "redb", @@ -2322,6 +2323,12 @@ dependencies = [ "yansi", ] +[[package]] +name = "primes" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a61082d8bceecd71a3870e9162002bb75f7ba9c7aa8b76227e887782fef9c8" + [[package]] name = "proc-macro-crate" version = "0.1.5" diff --git a/Cargo.toml b/Cargo.toml index 1076ef232e..f562abdb07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ http = "0.2.6" lazy_static = "1.4.0" log = "0.4.14" mime_guess = "2.0.4" +primes = "0.3.0" rayon = "1.5.1" redb = "0.7.0" regex = "1.6.0" diff --git a/src/ordinal.rs b/src/ordinal.rs index 09a87d8ae5..1dc9baeb2e 100644 --- a/src/ordinal.rs +++ b/src/ordinal.rs @@ -52,6 +52,10 @@ impl Ordinal { self.into() } + pub(crate) fn prime(self) -> bool { + primes::is_prime(self.0) + } + pub(crate) fn name(self) -> String { let mut x = Self::SUPPLY - self.0; let mut name = String::new(); diff --git a/src/subcommand/server/templates/ordinal.rs b/src/subcommand/server/templates/ordinal.rs index 2d570dd849..22a69a3758 100644 --- a/src/subcommand/server/templates/ordinal.rs +++ b/src/subcommand/server/templates/ordinal.rs @@ -36,6 +36,7 @@ mod tests {
period
0
offset
0
rarity
mythic
+
prime
false
time
1970-01-01 00:00:00
percentile
0%
@@ -47,32 +48,14 @@ mod tests { } #[test] - fn ordinal_previous() { - assert_eq!( + fn two_is_prime() { + assert_regex_match!( OrdinalHtml { - ordinal: Ordinal::LAST, + ordinal: Ordinal(2), blocktime: Blocktime::Confirmed(0), } .to_string(), - " -

Ordinal 2099999997689999

-
-
decimal
6929999.0
-
degree
5°209999′1007″0‴
-
name
a
-
block
6929999
-
cycle
5
-
epoch
32
-
period
3437
-
offset
0
-
rarity
uncommon
-
time
1970-01-01 00:00:00
-
percentile
100%
-
- prev - next - " - .unindent() + ".*
prime
true
.*", ); } @@ -96,6 +79,7 @@ mod tests {
period
0
offset
1
rarity
common
+
prime
false
time
1970-01-01 00:00:00
percentile
0.000000000000047619047671428595%
diff --git a/templates/ordinal.html b/templates/ordinal.html index 9d0f010511..a1da475bc1 100644 --- a/templates/ordinal.html +++ b/templates/ordinal.html @@ -9,6 +9,7 @@

Ordinal {{ self.ordinal.n() }}

period
{{ self.ordinal.period() }}
offset
{{ self.ordinal.third() }}
rarity
{{ self.ordinal.rarity() }}
+
prime
{{ self.ordinal.prime() }}
time
{{ self.blocktime }}
percentile
{{ self.ordinal.percentile() }}