"http",
"http-signature-normalization-actix",
"itertools",
- "lazy_static",
"lemmy_api_common",
"lemmy_apub",
"lemmy_apub_lib",
"http",
"http-signature-normalization-actix",
"itertools",
- "lazy_static",
"lemmy_api_common",
"lemmy_apub",
"lemmy_apub_lib",
"http",
"http-signature-normalization-actix",
"itertools",
- "lazy_static",
"lemmy_api_common",
"lemmy_apub_lib",
"lemmy_db_schema",
"lemmy_utils",
"lemmy_websocket",
"log",
+ "once_cell",
"percent-encoding",
"rand 0.8.4",
"reqwest",
"http",
"http-signature-normalization-actix",
"http-signature-normalization-reqwest",
- "lazy_static",
"lemmy_apub_lib_derive",
"lemmy_utils",
"log",
+ "once_cell",
"openssl",
"reqwest",
"serde",
"diesel",
"diesel-derive-newtype",
"diesel_migrations",
- "lazy_static",
"lemmy_apub_lib",
"lemmy_utils",
"log",
+ "once_cell",
"regex",
"serde",
"serde_json",
"awc",
"chrono",
"diesel",
- "lazy_static",
"lemmy_api_common",
"lemmy_apub",
"lemmy_db_schema",
"lemmy_utils",
"lemmy_websocket",
"log",
+ "once_cell",
"rss",
"serde",
"sha2",
"http",
"itertools",
"jsonwebtoken",
- "lazy_static",
"lettre",
"log",
+ "once_cell",
"openssl",
"percent-encoding",
"rand 0.8.4",
rand = "0.8.4"
strum = "0.21.0"
strum_macros = "0.21.1"
-lazy_static = "1.4.0"
url = { version = "2.2.2", features = ["serde"] }
openssl = "0.10.36"
http = "0.2.5"
rand = "0.8.4"
strum = "0.21.0"
strum_macros = "0.21.1"
-lazy_static = "1.4.0"
url = { version = "2.2.2", features = ["serde"] }
openssl = "0.10.36"
http = "0.2.5"
background-jobs = "0.9.1"
reqwest = { version = "0.11.4", features = ["json"] }
html2md = "0.2.13"
-lazy_static = "1.4.0"
+once_cell = "1.8.0"
[dev-dependencies]
serial_test = "0.5.1"
+use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
-lazy_static! {
- static ref CONTEXT: Vec<serde_json::Value> =
- serde_json::from_str(include_str!("../assets/lemmy/context.json")).expect("parse context");
-}
+static CONTEXT: Lazy<Vec<serde_json::Value>> = Lazy::new(|| {
+ serde_json::from_str(include_str!("../assets/lemmy/context.json")).expect("parse context")
+});
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct WithContext<T> {
impl<T> WithContext<T> {
pub(crate) fn new(inner: T) -> WithContext<T> {
WithContext {
- context: CONTEXT.clone(),
+ context: (*CONTEXT).clone(),
inner,
}
}
pub mod objects;
pub mod protocol;
-#[macro_use]
-extern crate lazy_static;
-
/// Checks if the ID is allowed for sending or receiving.
///
/// In particular, it checks for:
log = "0.4.14"
base64 = "0.13.0"
openssl = "0.10.36"
-lazy_static = "1.4.0"
+once_cell = "1.8.0"
http = "0.2.5"
sha2 = "0.9.8"
actix-web = { version = "4.0.0-beta.9", default-features = false }
-#[macro_use]
-extern crate lazy_static;
-
pub mod activity_queue;
pub mod data;
pub mod object_id;
LemmyError,
};
use log::info;
+use once_cell::sync::Lazy;
use reqwest::{Client, StatusCode};
use serde::{Deserialize, Serialize};
use std::{
/// fetch through the search). This should be configurable.
static REQUEST_LIMIT: i32 = 25;
-lazy_static! {
- static ref CLIENT: Client = Client::builder()
+static CLIENT: Lazy<Client> = Lazy::new(|| {
+ Client::builder()
.user_agent(build_user_agent(&Settings::get()))
.build()
- .expect("Couldn't build client");
-}
+ .expect("Couldn't build client")
+});
/// We store Url on the heap because it is quite large (88 bytes).
#[derive(Clone, PartialEq, Serialize, Deserialize, Debug)]
use http_signature_normalization_reqwest::prelude::{Config, SignExt};
use lemmy_utils::LemmyError;
use log::debug;
+use once_cell::sync::Lazy;
use openssl::{
hash::MessageDigest,
pkey::PKey,
use std::str::FromStr;
use url::Url;
-lazy_static! {
- static ref CONFIG2: ConfigActix = ConfigActix::new();
- static ref HTTP_SIG_CONFIG: Config = Config::new();
-}
+static CONFIG2: Lazy<ConfigActix> = Lazy::new(ConfigActix::new);
+static HTTP_SIG_CONFIG: Lazy<Config> = Lazy::new(Config::new);
/// Creates an HTTP post request to `inbox_url`, with the given `client` and `headers`, and
/// `activity` as request body. The request is signed with `private_key` and then sent.
url = { version = "2.2.2", features = ["serde"] }
diesel-derive-newtype = "0.1.2"
regex = "1.5.4"
-lazy_static = "1.4.0"
+once_cell = "1.8.0"
strum = "0.21.0"
strum_macros = "0.21.1"
sha2 = "0.9.8"
extern crate diesel;
#[macro_use]
extern crate diesel_derive_newtype;
-#[macro_use]
-extern crate lazy_static;
// this is used in tests
#[allow(unused_imports)]
#[macro_use]
use chrono::NaiveDateTime;
use diesel::{Connection, PgConnection};
use lemmy_utils::ApiError;
+use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::{env, env::VarError};
chrono::prelude::Utc::now().naive_utc()
}
-lazy_static! {
- static ref EMAIL_REGEX: Regex =
- Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$")
- .expect("compile email regex");
-}
+static EMAIL_REGEX: Lazy<Regex> = Lazy::new(|| {
+ Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$")
+ .expect("compile email regex")
+});
pub mod functions {
use diesel::sql_types::*;
awc = { version = "3.0.0-beta.8", default-features = false }
url = { version = "2.2.2", features = ["serde"] }
strum = "0.21.0"
-lazy_static = "1.4.0"
+once_cell = "1.8.0"
use lemmy_db_views_actor::person_mention_view::{PersonMentionQueryBuilder, PersonMentionView};
use lemmy_utils::{claims::Claims, utils::markdown_to_html, LemmyError};
use lemmy_websocket::LemmyContext;
+use once_cell::sync::Lazy;
use rss::{
extension::dublincore::DublinCoreExtensionBuilder,
ChannelBuilder,
.route("/feeds/local.xml", web::get().to(get_local_feed));
}
-lazy_static! {
- static ref RSS_NAMESPACE: HashMap<String, String> = {
- let mut h = HashMap::new();
- h.insert(
- "dc".to_string(),
- rss::extension::dublincore::NAMESPACE.to_string(),
- );
- h
- };
-}
+static RSS_NAMESPACE: Lazy<HashMap<String, String>> = Lazy::new(|| {
+ let mut h = HashMap::new();
+ h.insert(
+ "dc".to_string(),
+ rss::extension::dublincore::NAMESPACE.to_string(),
+ );
+ h
+});
async fn get_all_feed(
info: web::Query<Params>,
-#[macro_use]
-extern crate lazy_static;
-
pub mod feeds;
pub mod images;
pub mod nodeinfo;
serde_json = { version = "1.0.68", features = ["preserve_order"] }
thiserror = "1.0.29"
comrak = { version = "0.12.1", default-features = false }
-lazy_static = "1.4.0"
+once_cell = "1.8.0"
openssl = "0.10.36"
url = { version = "2.2.2", features = ["serde"] }
actix-web = { version = "4.0.0-beta.9", default-features = false, features = ["rustls"] }
#[macro_use]
-extern crate lazy_static;
-#[macro_use]
extern crate strum_macros;
#[macro_use]
extern crate smart_default;
use crate::{location_info, settings::structs::Settings, LemmyError};
use anyhow::{anyhow, Context};
use deser_hjson::from_str;
+use once_cell::sync::Lazy;
use regex::{Regex, RegexBuilder};
use std::{env, fs, io::Error, sync::RwLock};
static DEFAULT_CONFIG_FILE: &str = "config/config.hjson";
-lazy_static! {
- static ref SETTINGS: RwLock<Settings> =
- RwLock::new(Settings::init().expect("Failed to load settings file"));
- static ref WEBFINGER_REGEX: Regex = Regex::new(&format!(
+static SETTINGS: Lazy<RwLock<Settings>> =
+ Lazy::new(|| RwLock::new(Settings::init().expect("Failed to load settings file")));
+static WEBFINGER_REGEX: Lazy<Regex> = Lazy::new(|| {
+ Regex::new(&format!(
"^acct:([a-z0-9_]{{3,}})@{}$",
Settings::get().hostname
))
- .expect("compile webfinger regex");
-}
+ .expect("compile webfinger regex")
+});
impl Settings {
/// Reads config from configuration file.
use actix_web::dev::ConnectionInfo;
use chrono::{DateTime, FixedOffset, NaiveDateTime};
use itertools::Itertools;
+use once_cell::sync::Lazy;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use regex::Regex;
use url::Url;
-lazy_static! {
- static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").expect("compile regex");
-
- static ref USERNAME_MATCHES_REGEX: Regex = Regex::new(r"/u/[a-zA-Z][0-9a-zA-Z_]*").expect("compile regex");
- // TODO keep this old one, it didn't work with port well tho
- // static ref MENTIONS_REGEX: Regex = Regex::new(r"@(?P<name>[\w.]+)@(?P<domain>[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)").expect("compile regex");
- static ref MENTIONS_REGEX: Regex = Regex::new(r"@(?P<name>[\w.]+)@(?P<domain>[a-zA-Z0-9._:-]+)").expect("compile regex");
- static ref VALID_ACTOR_NAME_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex");
- static ref VALID_POST_TITLE_REGEX: Regex = Regex::new(r".*\S.*").expect("compile regex");
- static ref VALID_MATRIX_ID_REGEX: Regex = Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex");
- // taken from https://en.wikipedia.org/wiki/UTM_parameters
- static ref CLEAN_URL_PARAMS_REGEX: Regex = Regex::new(r"^utm_source|utm_medium|utm_campaign|utm_term|utm_content|gclid|gclsrc|dclid|fbclid$").expect("compile regex");
-}
+static MENTIONS_REGEX: Lazy<Regex> = Lazy::new(|| {
+ Regex::new(r"@(?P<name>[\w.]+)@(?P<domain>[a-zA-Z0-9._:-]+)").expect("compile regex")
+});
+static VALID_ACTOR_NAME_REGEX: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex"));
+static VALID_POST_TITLE_REGEX: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r".*\S.*").expect("compile regex"));
+static VALID_MATRIX_ID_REGEX: Lazy<Regex> = Lazy::new(|| {
+ Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex")
+});
+// taken from https://en.wikipedia.org/wiki/UTM_parameters
+static CLEAN_URL_PARAMS_REGEX: Lazy<Regex> = Lazy::new(|| {
+ Regex::new(r"^utm_source|utm_medium|utm_campaign|utm_term|utm_content|gclid|gclsrc|dclid|fbclid$")
+ .expect("compile regex")
+});
pub fn naive_from_unix(time: i64) -> NaiveDateTime {
NaiveDateTime::from_timestamp(time, 0)