Skip to content

Commit

Permalink
feat(deps): remove once_cell
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Aug 8, 2024
1 parent 18d57ba commit 9942a57
Show file tree
Hide file tree
Showing 33 changed files with 76 additions and 74 deletions.
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.0.1"
edition = "2021"
license = "MPL-2.0"
authors = ["Florian Dieminger <[email protected]>"]
rust-version = "1.80"

[workspace]
resolver = "2"
Expand All @@ -29,6 +30,7 @@ version = "0.0.1"
edition = "2021"
license = "MPL-2.0"
authors = ["Florian Dieminger <[email protected]>"]
rust-version = "1.80"

[dependencies]
anyhow = "1"
Expand Down
1 change: 1 addition & 0 deletions crates/css-definition-syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
rust-version.workspace = true

[dependencies]
thiserror = "1"
1 change: 1 addition & 0 deletions crates/css-syntax-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
rust-version.workspace = true

[dependencies]
regress = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion crates/css-syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
rust-version.workspace = true

[dependencies]
once_cell = "1"
thiserror = "1"
regress = "0.10"
serde_json = { version = "1", features = ["preserve_order"] }
Expand Down
8 changes: 4 additions & 4 deletions crates/css-syntax/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt::Write;
use std::fs;
use std::sync::LazyLock;

use css_definition_syntax::generate::{self, GenerateOptions};
use css_definition_syntax::parser::{parse, CombinatorType, Multiplier, Node, Type};
use css_definition_syntax::walk::{walk, WalkOptions};
use css_syntax_types::{Css, CssValueType, CssValuesItem};
use once_cell::sync::Lazy;
#[cfg(all(feature = "rari", not(test)))]
use rari_types::globals::data_dir;
use serde::Serialize;

use crate::error::SyntaxError;

static CSS_REF: Lazy<BTreeMap<String, Css>> = Lazy::new(|| {
static CSS_REF: LazyLock<BTreeMap<String, Css>> = LazyLock::new(|| {
#[cfg(test)]
{
let package_path = std::path::Path::new("package");
Expand Down Expand Up @@ -64,7 +64,7 @@ pub struct Flattened {
// This relies on the ordered names of CSS_REF.
// "css-values-5" comes after "css-values" and therefore the updated
// overlapping values in "css-values-5" are ignored.
static FLATTENED: Lazy<Flattened> = Lazy::new(|| {
static FLATTENED: LazyLock<Flattened> = LazyLock::new(|| {
let mut all = Flattened::default();
let mut entries = CSS_REF.iter().collect::<Vec<_>>();
entries.sort_by(|a, b| {
Expand Down Expand Up @@ -746,7 +746,7 @@ fn get_nodes_for_syntaxes(
mod test {
use super::*;

static TOOLTIPS: Lazy<HashMap<LinkedToken, String>> = Lazy::new(|| {
static TOOLTIPS: LazyLock<HashMap<LinkedToken, String>> = LazyLock::new(|| {
[(LinkedToken::Asterisk, "Asterisk: the entity may occur zero, one or several times".to_string()),
(LinkedToken::Plus, "Plus: the entity may occur one or several times".to_string()),
(LinkedToken::QuestionMark, "Question mark: the entity is optional".to_string()),
Expand Down
2 changes: 1 addition & 1 deletion crates/diff-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
rust-version.workspace = true

[dependencies]
anyhow = "1"
Expand All @@ -18,5 +19,4 @@ ansi-to-html = "0.2"
itertools = "0.13"
similar = "2"
regex = "1"
once_cell = "1"
htmldiff = "0.1"
8 changes: 5 additions & 3 deletions crates/diff-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::sync::LazyLock;

use anyhow::{anyhow, Error};
use clap::{Args, Parser, Subcommand};
Expand All @@ -12,7 +13,6 @@ use ignore::types::TypesBuilder;
use ignore::WalkBuilder;
use itertools::Itertools;
use jsonpath_lib::Compiled;
use once_cell::sync::Lazy;
use prettydiff::diff_words;
use regex::Regex;
use serde_json::Value;
Expand Down Expand Up @@ -174,8 +174,10 @@ const IGNORE: &[&str] = &[
"doc.other_translations",
];

static WS_DIFF: Lazy<Regex> = Lazy::new(|| Regex::new(r#"(?<x>>)[\n ]+|[\n ]+(?<y></)"#).unwrap());
static DATA_FLAW_SRC: Lazy<Regex> = Lazy::new(|| Regex::new(r#" data-flaw-src="[^"]+""#).unwrap());
static WS_DIFF: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"(?<x>>)[\n ]+|[\n ]+(?<y></)"#).unwrap());
static DATA_FLAW_SRC: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#" data-flaw-src="[^"]+""#).unwrap());

fn full_diff(lhs: &Value, rhs: &Value, path: &[PathIndex], diff: &mut BTreeMap<String, String>) {
if path.len() == 1 {
Expand Down
1 change: 1 addition & 0 deletions crates/rari-data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
rust-version.workspace = true

[dependencies]
rari-utils = { path = "../rari-utils" }
Expand Down
2 changes: 1 addition & 1 deletion crates/rari-deps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
rust-version.workspace = true

[dependencies]
rari-utils = { path = "../rari-utils" }
once_cell = "1"
thiserror = "1"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/rari-doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
rust-version.workspace = true

[dependencies]
thiserror = "1"
Expand All @@ -16,7 +17,6 @@ pest = "2"
pest_derive = "2"
regex = "1"
validator = { version = "0.18", features = ["derive"] }
once_cell = "1"
scraper = { version = "0.19", features = ["deterministic"] }
chrono = { version = "0.4", features = ["serde"] }
lol_html = "1"
Expand Down
5 changes: 3 additions & 2 deletions crates/rari-doc/src/baseline.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use once_cell::sync::Lazy;
use std::sync::LazyLock;

use rari_data::baseline::{SupportStatus, WebFeatures};
use rari_types::globals::data_dir;
use tracing::warn;

static WEB_FEATURES: Lazy<Option<WebFeatures>> = Lazy::new(|| {
static WEB_FEATURES: LazyLock<Option<WebFeatures>> = LazyLock::new(|| {
let web_features = WebFeatures::from_file(
&data_dir()
.join("web-features")
Expand Down
15 changes: 7 additions & 8 deletions crates/rari-doc/src/cached_readers.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock};
use std::sync::{Arc, LazyLock, OnceLock, RwLock};

use once_cell::sync::{Lazy, OnceCell};
use rari_types::globals::{blog_root, cache_content, content_root, curriculum_root};
use rari_types::locale::Locale;
use rari_utils::io::read_to_string;
Expand All @@ -18,20 +17,20 @@ use crate::sidebars::jsref;
use crate::utils::split_fm;
use crate::walker::{read_docs_parallel, walk_builder};

pub static STATIC_PAGE_FILES: OnceCell<HashMap<PathBuf, Page>> = OnceCell::new();
pub static CACHED_PAGE_FILES: OnceCell<Arc<RwLock<HashMap<PathBuf, Page>>>> = OnceCell::new();
pub static STATIC_PAGE_FILES: OnceLock<HashMap<PathBuf, Page>> = OnceLock::new();
pub static CACHED_PAGE_FILES: OnceLock<Arc<RwLock<HashMap<PathBuf, Page>>>> = OnceLock::new();
type SidebarFilesCache = Arc<RwLock<HashMap<(String, Locale), Arc<MetaSidebar>>>>;
pub static CACHED_SIDEBAR_FILES: Lazy<SidebarFilesCache> =
Lazy::new(|| Arc::new(RwLock::new(HashMap::new())));
pub static CACHED_CURRICULUM: OnceCell<CurriculumFiles> = OnceCell::new();
pub static CACHED_SIDEBAR_FILES: LazyLock<SidebarFilesCache> =
LazyLock::new(|| Arc::new(RwLock::new(HashMap::new())));
pub static CACHED_CURRICULUM: OnceLock<CurriculumFiles> = OnceLock::new();

#[derive(Debug, Default, Clone)]
pub struct BlogFiles {
pub posts: HashMap<String, Page>,
pub authors: HashMap<String, Arc<Author>>,
pub sorted_meta: Vec<BlogPostBuildMeta>,
}
pub static BLOG_FILES: OnceCell<BlogFiles> = OnceCell::new();
pub static BLOG_FILES: OnceLock<BlogFiles> = OnceLock::new();

#[derive(Debug, Default, Clone)]
pub struct CurriculumFiles {
Expand Down
8 changes: 4 additions & 4 deletions crates/rari-doc/src/docs/curriculum.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use once_cell::sync::Lazy;
use rari_types::fm_types::{FeatureStatus, PageType};
use rari_types::globals::curriculum_root;
use rari_types::locale::Locale;
Expand Down Expand Up @@ -122,8 +121,9 @@ impl PageReader for CurriculumPage {
}
}

static TITLE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r#"^[\w\n]*#\s+(.*)\n"#).unwrap());
static SLUG_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r#"(\d+-|\.md$|\/0?-?README)"#).unwrap());
static TITLE_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r#"^[\w\n]*#\s+(.*)\n"#).unwrap());
static SLUG_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"(\d+-|\.md$|\/0?-?README)"#).unwrap());

fn curriculum_file_to_slug(file: &Path) -> String {
SLUG_RE.replace_all(&file.to_string_lossy(), "").to_string()
Expand Down
4 changes: 2 additions & 2 deletions crates/rari-doc/src/helpers/css_info.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::Write;
use std::sync::OnceLock;

use itertools::Itertools;
use once_cell::sync::OnceCell;
use rari_l10n::l10n_json_data;
use rari_types::globals::data_dir;
use rari_types::locale::Locale;
Expand Down Expand Up @@ -41,7 +41,7 @@ impl MDNDataFiles {
}
}

pub static MDN_DATA_FILES: OnceCell<MDNDataFiles> = OnceCell::new();
pub static MDN_DATA_FILES: OnceLock<MDNDataFiles> = OnceLock::new();

pub fn mdn_data_files() -> &'static MDNDataFiles {
MDN_DATA_FILES.get_or_init(|| match MDNDataFiles::init() {
Expand Down
6 changes: 3 additions & 3 deletions crates/rari-doc/src/helpers/json_data.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::sync::OnceLock;

use once_cell::sync::OnceCell;
use rari_types::globals::content_root;
use rari_utils::io::read_to_string;
use serde::Deserialize;
Expand All @@ -10,7 +10,7 @@ pub struct InterfaceData {
pub inh: String,
}

pub static JSON_DATA_INTERFACE: OnceCell<HashMap<String, InterfaceData>> = OnceCell::new();
pub static JSON_DATA_INTERFACE: OnceLock<HashMap<String, InterfaceData>> = OnceLock::new();

pub fn json_data_interface() -> &'static HashMap<String, InterfaceData> {
JSON_DATA_INTERFACE.get_or_init(|| {
Expand Down Expand Up @@ -40,7 +40,7 @@ pub struct GroupData {
pub tutorial: Vec<String>,
}

pub static JSON_DATA_GROUP: OnceCell<HashMap<String, GroupData>> = OnceCell::new();
pub static JSON_DATA_GROUP: OnceLock<HashMap<String, GroupData>> = OnceLock::new();

pub fn json_data_group() -> &'static HashMap<String, GroupData> {
JSON_DATA_GROUP.get_or_init(|| {
Expand Down
6 changes: 3 additions & 3 deletions crates/rari-doc/src/helpers/web_ext_examples.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::sync::LazyLock;

use once_cell::sync::Lazy;
use rari_types::globals::data_dir;
use rari_utils::io::read_to_string;
use serde::Deserialize;
Expand All @@ -20,7 +20,7 @@ pub struct WebExtExamplesData {
pub by_module_and_api: HashMap<&'static str, Vec<&'static WebExtExample>>,
}

pub static WEB_EXT_EXAMPLES_JSON: Lazy<Vec<WebExtExample>> = Lazy::new(|| {
pub static WEB_EXT_EXAMPLES_JSON: LazyLock<Vec<WebExtExample>> = LazyLock::new(|| {
match read_to_string(data_dir().join("web_ext_examples/data.json"))
.map_err(DocError::from)
.and_then(|s| serde_json::from_str(&s).map_err(DocError::from))
Expand All @@ -37,7 +37,7 @@ pub fn web_ext_examples_json() -> &'static [WebExtExample] {
&WEB_EXT_EXAMPLES_JSON
}

pub static WEB_EXT_EXAMPLES_DATA: Lazy<WebExtExamplesData> = Lazy::new(|| {
pub static WEB_EXT_EXAMPLES_DATA: LazyLock<WebExtExamplesData> = LazyLock::new(|| {
let mut by_module = HashMap::new();
for example in web_ext_examples_json() {
for js_api in &example.javascript_apis {
Expand Down
6 changes: 3 additions & 3 deletions crates/rari-doc/src/html/sidebar.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::collections::HashMap;
pub use std::ops::Deref;
use std::sync::{Arc, RwLock};
use std::sync::{Arc, LazyLock, RwLock};

use once_cell::sync::Lazy;
use rari_types::fm_types::PageType;
use rari_types::globals::cache_content;
use rari_types::locale::Locale;
Expand Down Expand Up @@ -31,7 +30,8 @@ fn cache_side_bar(sidebar: &str) -> bool {

type SidebarCache = Arc<RwLock<HashMap<Locale, HashMap<String, String>>>>;

static SIDEBAR_CACHE: Lazy<SidebarCache> = Lazy::new(|| Arc::new(RwLock::new(HashMap::new())));
static SIDEBAR_CACHE: LazyLock<SidebarCache> =
LazyLock::new(|| Arc::new(RwLock::new(HashMap::new())));

pub fn expand_details_and_mark_current_for_inline_sidebar(
html: &mut Html,
Expand Down
Loading

0 comments on commit 9942a57

Please sign in to comment.