From 52794f9153186b3033beb4b81ef42d1711a9904d Mon Sep 17 00:00:00 2001 From: u <@> Date: Tue, 10 Mar 2026 12:48:47 +0200 Subject: lint --- src/lib.rs | 14 ++++++------ src/solar.rs | 75 +++++++++++++++++++++++++++++------------------------------- 2 files changed, 43 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 0576324..c73d61b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,14 +54,16 @@ async fn fetch(req: Request, env: Env, _ctx: Context) -> Result { pre { @for x in a.split('\n').map(|l| { let l = l.trim(); - if let Some(c) = re.captures(l) { + re.captures(l) + .map_or_else(|| html! { (PreEscaped(l)) "\n" }, + |c| { let (m, d, y) = (c.get(1), c.get(2), c.get(3)); let f = |x: Option| x.unwrap().as_str().parse().unwrap(); let (y, m, d): (usize, usize, usize) = (f(y) + 2000, f(m), f(d)); let s = solar(y, m, d); let (dowc, dowl) = dow(y, m, d); let (y, m, d, t) = (s.year, s.month, s.day, s.term); - let href = l.replace("/", "_"); + let href = l.replace('/', "_"); html! { (PreEscaped("")) a name=(href) { } @@ -73,9 +75,7 @@ async fn fetch(req: Request, env: Env, _ctx: Context) -> Result { } (PreEscaped("
"))
                             }
-                        } else {
-                            html! { (PreEscaped(l)) "\n" }
-                        }
+                        })
                     }) {
                         (x)
                     }
@@ -112,7 +112,7 @@ async fn fetch(req: Request, env: Env, _ctx: Context) -> Result {
 }
 
 fn header() -> Markup {
-    let css = r#"/* i dont know css im so fucking sorry ill fix it l8r */
+    let css = r"/* i dont know css im so fucking sorry ill fix it l8r */
 pre {
   white-space: pre-wrap;
   white-space: -moz-pre-wrap;
@@ -198,7 +198,7 @@ body {
   max-width: 960px;
   margin-left: auto;
   margin-right: auto;
-}"#;
+}";
     html! {
         (DOCTYPE)
         style { (PreEscaped(css)) }
diff --git a/src/solar.rs b/src/solar.rs
index 06cffb3..3cf0c95 100644
--- a/src/solar.rs
+++ b/src/solar.rs
@@ -4,12 +4,11 @@
 #![allow(dead_code)]
 
 // based on https://prospertimes.neocities.org/solarterms.js
-use lazy_static::lazy_static;
 use num::cast;
 use std::{
-    f64::consts::PI,
     mem::MaybeUninit,
     ops::{Div, Rem},
+    sync::LazyLock,
 };
 
 // this is so stupid. i should not have to put pub every single line
@@ -97,14 +96,11 @@ fn compute_ang(jd: f64) -> f64 {
     let Lmean = (280.46646 + (36000.76983 * T) + (0.0003032 * T * T)) % 360.;
     let M = (357.52911 + (35999.05029 * T) - (0.0001537 * T * T)) % 360.;
     let C = ((1.914602 - (0.004817 * T) - (0.000014 * T * T))
-        * (M * PI / 180.).sin())
-        + ((0.019993 - (0.000101 * T)) * (2. * M * PI / 180.).sin())
-        + (0.000289 * (3. * M * PI / 180.).sin());
+        * (M.to_radians()).sin())
+        + ((0.019993 - (0.000101 * T)) * (2. * M.to_radians()).sin())
+        + (0.000289 * (3. * M.to_radians()).sin());
     let Ltrue = Lmean + C;
-    let Lapp = Ltrue
-        - 0.00569
-        - (0.00478 * ((125.04 - 1934.136 * T) * PI / 180.).sin());
-    Lapp
+    Ltrue - 0.00569 - (0.00478 * ((125.04 - 1934.136 * T).to_radians()).sin())
 }
 
 #[inline(always)]
@@ -120,7 +116,7 @@ fn bisect(
     T: Into + Copy,
 {
     while lo <= hi {
-        let mid = ((*lo + *hi) / 2.).floor();
+        let mid = f64::midpoint(*lo, *hi).floor();
         if compute_ang(JD!(y, m, base.into() + mid * scale.into())) < target {
             *lo = mid + 1.;
         } else {
@@ -171,7 +167,7 @@ where
 {
     let (a, to, zero) = (a.as_(), to.as_(), zero.as_());
     let tmp = a + (to - zero);
-    (tmp - to * (tmp >= to) as isize) as usize
+    (tmp - to * isize::from(tmp >= to)) as usize
 }
 
 #[inline(always)]
@@ -199,9 +195,9 @@ fn stday(i: usize, y: usize) -> f64 {
     const YEARS: usize = 200;
     // rust doesnt have (*a)[n], | @ least ill have2 use a cr8 4 it
     // also lazy_static doesnt work with mutables (im not using mutex)
-    assert!(y < UNIT_YR + YEARS && UNIT_YR <= y);
     static mut STDAYS: Vec = vec![];
     static mut INIT: bool = false;
+    assert!((UNIT_YR..YEARS + UNIT_YR).contains(&y));
     unsafe {
         if !INIT {
             STDAYS = vec![0.; YEARS * TERMS.len()];
@@ -220,47 +216,47 @@ fn stday(i: usize, y: usize) -> f64 {
     }
 }
 
-lazy_static! {
-    static ref GANZHIS: Vec = {
-        const gan: [char; 10] = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'];
-        const zhi: [char; 12] = [ '子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉',
-                                  '戌', '亥', ];
-        let mut tmp: Vec = vec![];
-        tmp.reserve(60);
-        (0..60).for_each(|i| {
-            // looks so much worse than using format!()
-            // cant be bothered to benchmark
-            let mut s = gan[i % 10].to_string();
-            s.push(zhi[i % 12]);
-            tmp.push(s);
-        });
-        tmp
-    };
-}
+static GANZHIS: LazyLock> = LazyLock::new(|| {
+    const gan: [char; 10] =
+        ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'];
+    const zhi: [char; 12] = [
+        '子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥',
+    ];
+    let mut tmp: Vec = Vec::with_capacity(60);
+    (0..60).for_each(|i| {
+        // looks so much worse than using format!()
+        // cant be bothered to benchmark
+        let mut s = gan[i % 10].to_string();
+        s.push(zhi[i % 12]);
+        tmp.push(s);
+    });
+    tmp
+});
 
+#[must_use]
 pub fn ganzhi(i: usize) -> &'static str {
     &GANZHIS[i]
 }
 
 #[inline(always)]
-fn int(x: f64) -> usize {
+const fn int(x: f64) -> usize {
     x as usize // x.as_int_unchecked() // wont work on wasm
 }
 
-lazy_static! {
-    static ref JIAZI: usize = int(JD!(UNIT_YR, 1, 31));
-}
+static JIAZI: LazyLock = LazyLock::new(|| int(JD!(UNIT_YR, 1, 31)));
+
+#[must_use]
 pub fn solar(y: usize, m: usize, d: usize) -> SexagenaryDate {
     let jdf = JD!(y, m, d);
     let jd = int(jdf);
     let a = compute_ang(jdf);
     let ygz = (y
         - UNIT_YR
-        - ((m <= 2 && a < 316.) && (m < 2 || d < int(stday(2, y)))) as usize)
+        - usize::from((m <= 2 && a < 316.) && (m < 2 || d < int(stday(2, y)))))
         % 60;
     let rem = a % 15.;
     let div = int(a.div(15.).floor());
-    let mut dz = align((div + 1) / 2, 12, 9);
+    let mut dz = align(div.div_ceil(2), 12, 9);
     let mut termb = rem > 14.;
     let mut term: usize = unsafe { MaybeUninit::uninit().assume_init() };
     if termb {
@@ -268,13 +264,13 @@ pub fn solar(y: usize, m: usize, d: usize) -> SexagenaryDate {
         let termday = stday(term, y);
         termb = d == int(termday);
         if (div & 1) == 0 {
-            dz += termb as usize;
+            dz += usize::from(termb);
             dz = align(dz, 12, 12);
         }
     }
     let mut tmp = ygz.rem(5);
     tmp = tmp * 2 + 2;
-    tmp -= 10 * (tmp == 10) as usize;
+    tmp -= 10 * usize::from(tmp == 10);
     let mgz = mod2ganzhi(tmp + align(dz, 12, 2).rem(10), dz);
     let dgz = (jd - *JIAZI).rem(60);
     SexagenaryDate {
@@ -286,12 +282,13 @@ pub fn solar(y: usize, m: usize, d: usize) -> SexagenaryDate {
 }
 
 // https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Disparate_variation
+#[must_use]
 pub fn dow(y: usize, mut m: usize, d: usize) -> (&'static str, &'static str) {
-    let Y = y - (m <= 2) as usize;
+    let Y = y - usize::from(m <= 2);
     let y2 = Y % 100;
     let c = Y / 100;
     m += 9;
-    m -= 12 * (m >= 12) as usize;
+    m -= 12 * usize::from(m >= 12);
     let a = (d + (26 * (m + 1) - 2) / 10 + y2 + y2 / 4 + c / 4 - 2 * c) % 7;
     [
         ("日", "Sun"),
-- 
cgit v1.2.3