Skip to content

Commit

Permalink
replace lazy_static
Browse files Browse the repository at this point in the history
  • Loading branch information
ddboline committed Dec 26, 2023
1 parent 228e53b commit 6332b41
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_rust"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand Down
16 changes: 8 additions & 8 deletions fitbit_bot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[package]
name = "fitbit_bot"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
arc-swap = "1.2"
crossbeam-utils = "0.8"
fitbit_lib = {path="../fitbit_lib"}
garmin_lib = {path="../garmin_lib"}
garmin_utils = {path="../garmin_utils"}
futures = "0.3"
tokio = {version="1.35", features=["rt", "macros", "rt-multi-thread"]}
crossbeam-utils = "0.8"
lazy_static = "1.4"
parking_lot = "0.12"
log = "0.4"
anyhow = "1.0"
arc-swap = "1.2"
telegram-bot = {git = "https://github.com/ddboline/telegram-bot.git", tag="0.9.0-4", default_features=false}
once_cell = "1.0"
parking_lot = "0.12"
stack-string = { git = "https://github.com/ddboline/stack-string-rs.git", features=["postgres_types"], tag="0.9.2" }
telegram-bot = {git = "https://github.com/ddboline/telegram-bot.git", tag="0.9.0-4", default_features=false}
tokio = {version="1.35", features=["rt", "macros", "rt-multi-thread"]}

[dev-dependencies]
maplit = "1.0"
Expand Down
16 changes: 6 additions & 10 deletions fitbit_bot/src/telegram_bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Error;
use arc_swap::ArcSwap;
use crossbeam_utils::atomic::AtomicCell;
use futures::{StreamExt, TryStreamExt};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use log::debug;
use stack_string::{format_sstr, StackString};
use std::{collections::HashSet, sync::Arc};
Expand All @@ -23,11 +23,9 @@ use super::failure_count::FailureCount;
type WeightLock = AtomicCell<Option<ScaleMeasurement>>;
type Userids = ArcSwap<HashSet<UserId>>;

lazy_static! {
static ref LAST_WEIGHT: WeightLock = AtomicCell::new(None);
static ref USERIDS: Userids = ArcSwap::new(Arc::new(HashSet::new()));
static ref FAILURE_COUNT: FailureCount = FailureCount::new(5);
}
static LAST_WEIGHT: Lazy<WeightLock> = Lazy::new(|| AtomicCell::new(None));
static USERIDS: Lazy<Userids> = Lazy::new(|| ArcSwap::new(Arc::new(HashSet::new())));
static FAILURE_COUNT: Lazy<FailureCount> = Lazy::new(|| FailureCount::new(5));

#[derive(Clone)]
pub struct TelegramBot {
Expand Down Expand Up @@ -207,7 +205,7 @@ impl TelegramBot {
#[cfg(test)]
mod tests {
use anyhow::Error;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use maplit::hashset;
use parking_lot::Mutex;
use postgres_query::query;
Expand All @@ -225,9 +223,7 @@ mod tests {

use crate::telegram_bot::{TelegramBot, LAST_WEIGHT, USERIDS};

lazy_static! {
static ref DB_LOCK: Mutex<()> = Mutex::new(());
}
static DB_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));

#[tokio::test]
async fn test_process_message_text() -> Result<(), Error> {
Expand Down
4 changes: 2 additions & 2 deletions fitbit_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fitbit_lib"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -20,9 +20,9 @@ garmin_models = {path="../garmin_models"}
garmin_utils = {path="../garmin_utils"}
glob = "0.3"
itertools = "0.12"
lazy_static = "1.4"
log = "0.4"
maplit = "1.0"
once_cell = "1.0"
polars = {version="0.35", features=["temporal", "parquet", "lazy"]}
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.6", features=["deadpool"]}
rand = "0.8"
Expand Down
6 changes: 2 additions & 4 deletions fitbit_lib/src/fitbit_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use base64::{engine::general_purpose::STANDARD, Engine};
use crossbeam_utils::atomic::AtomicCell;
use futures::{future, future::try_join_all, stream::FuturesUnordered, TryStreamExt};
use itertools::Itertools;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use log::debug;
use maplit::hashmap;
use reqwest::{header::HeaderMap, Client, Response, Url};
Expand Down Expand Up @@ -38,9 +38,7 @@ use crate::{
GarminConnectHrData,
};

lazy_static! {
static ref CSRF_TOKEN: AtomicCell<Option<StackString>> = AtomicCell::new(None);
}
static CSRF_TOKEN: Lazy<AtomicCell<Option<StackString>>> = Lazy::new(|| AtomicCell::new(None));

#[derive(Default, Debug, Clone)]
pub struct FitbitClient {
Expand Down
3 changes: 1 addition & 2 deletions garmin_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_cli"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -19,7 +19,6 @@ garmin_parser={path="../garmin_parser"}
garmin_reports = {path="../garmin_reports"}
garmin_utils={path="../garmin_utils"}
itertools = "0.12"
lazy_static = "1.4"
log = "0.4"
race_result_analysis = {path="../race_result_analysis"}
rayon = "1.5"
Expand Down
3 changes: 1 addition & 2 deletions garmin_connect_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_connect_lib"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -14,7 +14,6 @@ fantoccini = {version="0.19", features=["rustls-tls"], default_features=false}
futures = "0.3"
garmin_lib = {path="../garmin_lib"}
itertools = "0.12"
lazy_static = "1.4"
log = "0.4"
reqwest = {version="0.11", features=["cookies", "json", "rustls-tls", "stream"], default_features=false}
serde = {version="1.0", features=["derive"]}
Expand Down
5 changes: 2 additions & 3 deletions garmin_http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "garmin_http"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

[dependencies]
anyhow = "1.0"
authorized_users = { git = "https://github.com/ddboline/auth_server_rust.git", tag="0.11.8"}
authorized_users = { git = "https://github.com/ddboline/auth_server_rust.git", tag="0.11.9"}
base64 = "0.21"
cookie = {version="0.18", features=["percent-encode"]}
derive_more = "0.99"
Expand All @@ -22,7 +22,6 @@ garmin_reports = {path="../garmin_reports"}
garmin_utils = {path="../garmin_utils"}
handlebars = "4.0"
itertools = "0.12"
lazy_static = "1.4"
log = "0.4"
maplit = "1.0"
parking_lot = "0.12"
Expand Down
4 changes: 2 additions & 2 deletions garmin_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_lib"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -11,7 +11,7 @@ derive_more = "0.99"
dirs = "5.0"
dotenv = "0.15"
envy = "0.4"
lazy_static = "1.4"
once_cell = "1.0"
postgres-types = {version="0.2", features=["with-time-0_3", "with-uuid-1", "with-serde_json-1", "derive"]}
serde = {version="1.0", features=["derive"]}
serde_json = "1.0"
Expand Down
6 changes: 2 additions & 4 deletions garmin_lib/src/date_time_wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use bytes::BytesMut;
use derive_more::{Deref, DerefMut, From, Into};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use postgres_types::{FromSql, IsNull, ToSql, Type};
use serde::{Deserialize, Serialize};
use std::fmt;
use time::{macros::datetime, OffsetDateTime};
use time_tz::{timezones::db::UTC, Tz};

lazy_static! {
static ref LOCAL_TZ: &'static Tz = time_tz::system::get_timezone().unwrap_or(UTC);
}
static LOCAL_TZ: Lazy<&'static Tz> = Lazy::new(|| time_tz::system::get_timezone().unwrap_or(UTC));

#[derive(
Serialize,
Expand Down
4 changes: 2 additions & 2 deletions garmin_models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_models"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2021"

Expand All @@ -17,8 +17,8 @@ garmin_lib = {path="../garmin_lib"}
garmin_utils = {path="../garmin_utils"}
itertools = "0.12"
json = "0.12"
lazy_static = "1.4"
log = "0.4"
once_cell = "1.0"
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.6", features=["deadpool"]}
rand = "0.8"
roxmltree = "0.19"
Expand Down
6 changes: 2 additions & 4 deletions garmin_models/src/garmin_file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{format_err, Error};
use avro_rs::{from_value, Codec, Reader, Schema, Writer};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use stack_string::{format_sstr, StackString};
use std::{collections::HashMap, fs::File, path::Path};
Expand All @@ -16,9 +16,7 @@ use crate::{
garmin_point::{GarminPoint, GARMIN_POINT_AVRO_SCHEMA},
};

lazy_static! {
static ref GARMIN_FILE_AVRO_SCHEMA: StackString = GarminFile::get_avro_schema();
}
static GARMIN_FILE_AVRO_SCHEMA: Lazy<StackString> = Lazy::new(GarminFile::get_avro_schema);

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct GarminFile {
Expand Down
2 changes: 1 addition & 1 deletion garmin_parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_parser"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions garmin_reports/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_reports"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -14,8 +14,8 @@ garmin_lib = {path="../garmin_lib"}
garmin_models = {path="../garmin_models"}
garmin_utils = {path="../garmin_utils"}
itertools = "0.12"
lazy_static = "1.4"
log = "0.4"
once_cell = "1.0"
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.6", features=["deadpool"]}
regex = "1.4"
stack-string = { git = "https://github.com/ddboline/stack-string-rs.git", features=["postgres_types", "rweb-openapi"], tag="0.9.2" }
Expand Down
16 changes: 7 additions & 9 deletions garmin_reports/src/garmin_constraints.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use derive_more::Deref;
use itertools::Itertools;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use stack_string::{format_sstr, StackString};
use time::{format_description::well_known::Rfc3339, macros::format_description, OffsetDateTime};
Expand All @@ -11,14 +11,12 @@ use garmin_utils::sport_types::get_sport_type_map;

use crate::garmin_report_options::{GarminReportAgg, GarminReportOptions};

lazy_static! {
static ref WEEK_REG: Regex =
Regex::new(r"(?P<year>\d{4})w(?P<week>\d{1,2})").expect("Bad regex");
static ref YMD_REG: Regex =
Regex::new(r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})").expect("Bad regex");
static ref YM_REG: Regex = Regex::new(r"(?P<year>\d{4})-(?P<month>\d{2})").expect("Bad regex");
static ref Y_REG: Regex = Regex::new(r"(?P<year>\d{4})").expect("Bad regex");
}
static WEEK_REG: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?P<year>\d{4})w(?P<week>\d{1,2})").expect("Bad regex"));
static YMD_REG: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})").expect("Bad regex"));
static YM_REG: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?P<year>\d{4})-(?P<month>\d{2})").expect("Bad regex"));
static Y_REG: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?P<year>\d{4})").expect("Bad regex"));

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum GarminConstraint {
Expand Down
4 changes: 2 additions & 2 deletions garmin_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "garmin_utils"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2021"

Expand All @@ -14,9 +14,9 @@ deadpool-postgres = "0.12"
fitparser = {git="https://github.com/ddboline/fitparse-rs.git", branch="time-0.3-0.5.2"}
flate2 = "1.0"
futures = "0.3"
lazy_static = "1.4"
log = "0.4"
num-traits = "0.2"
once_cell = "1.0"
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.6", features=["deadpool"]}
rand = "0.8"
serde = {version="1.0", features=["derive"]}
Expand Down
6 changes: 2 additions & 4 deletions garmin_utils/src/sport_types.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use anyhow::{format_err, Error};
use bytes::BytesMut;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use stack_string::StackString;
use std::{collections::HashMap, convert::TryFrom, fmt, str::FromStr};
use tokio_postgres::types::{FromSql, IsNull, ToSql, Type};

lazy_static! {
static ref SPORT_TYPE_MAP: HashMap<&'static str, SportTypes> = init_sport_type_map();
}
static SPORT_TYPE_MAP: Lazy<HashMap<&'static str, SportTypes>> = Lazy::new(init_sport_type_map);

#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(into = "StackString", try_from = "StackString")]
Expand Down
6 changes: 4 additions & 2 deletions race_result_analysis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "race_result_analysis"
version = "0.14.8"
version = "0.14.9"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -14,7 +14,6 @@ garmin_lib = {path="../garmin_lib"}
garmin_models = {path="../garmin_models"}
garmin_utils = {path="../garmin_utils"}
itertools = "0.12"
lazy_static = "1.4"
log = "0.4"
ndarray = "0.15"
parking_lot = "0.12"
Expand All @@ -28,3 +27,6 @@ time-tz = {version="2.0", features=["system"]}
tokio = {version="1.35", features=["rt", "macros", "rt-multi-thread"]}
tokio-postgres = {version = "0.7", features = ["with-time-0_3", "with-uuid-1"]}
uuid = { version = "1.0", features = ["serde", "v4"] }

[dev-dependencies]
once_cell = "1.0"
6 changes: 2 additions & 4 deletions race_result_analysis/src/race_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl From<GarminSummary> for RaceResults {
mod tests {
use anyhow::Error;
use futures::TryStreamExt;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use log::debug;
use parking_lot::Mutex;
use stack_string::format_sstr;
Expand All @@ -463,9 +463,7 @@ mod tests {
const WORLD_RECORD_ENTRIES: usize = 24;
const TEST_RACE_ENTRIES: usize = 214;

lazy_static! {
static ref DB_LOCK: Mutex<()> = Mutex::new(());
}
static DB_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));

fn get_test_race_result() -> RaceResults {
RaceResults {
Expand Down
Loading

0 comments on commit 6332b41

Please sign in to comment.