Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove lazy_static #373

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ Feel free to open an issue, discuss using GitHub discussions or open a PR.
[See CONTRIBUTING.md](https://github.com/Aleph-Alpha/ts-rs/blob/main/CONTRIBUTING.md)

### MSRV
The Minimum Supported Rust Version for this crate is 1.63.0
The Minimum Supported Rust Version for this crate is 1.74.1

License: MIT
3 changes: 1 addition & 2 deletions ts-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = [
"web-programming",
]
readme = "../README.md"
rust-version = "1.63.0"
rust-version = "1.74.1"

[features]
chrono-impl = ["chrono"]
Expand Down Expand Up @@ -60,5 +60,4 @@ smol_str = { version = "0.3", optional = true }
indexmap = { version = "2", optional = true }
ordered-float = { version = ">= 3, < 5", optional = true }
serde_json = { version = "1", optional = true }
lazy_static = { version = "1", default-features = false }
tokio = { version = "1", features = ["sync"], optional = true }
12 changes: 7 additions & 5 deletions ts-rs/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use std::{
fs::File,
io::{Seek, SeekFrom},
path::{Component, Path, PathBuf},
sync::Mutex,
sync::{Mutex, OnceLock},
};

pub use error::ExportError;
use lazy_static::lazy_static;
use path::diff_paths;
pub(crate) use recursive_export::export_all_into;

Expand All @@ -19,8 +18,11 @@ use crate::TS;
mod error;
mod path;

lazy_static! {
static ref EXPORT_PATHS: Mutex<HashMap<PathBuf, HashSet<String>>> = Mutex::new(HashMap::new());
static EXPORT_PATHS: OnceLock<Mutex<HashMap<PathBuf, HashSet<String>>>> =
OnceLock::new();

fn get_export_paths<'a>() -> &'a Mutex<HashMap<PathBuf, HashSet<String>>> {
EXPORT_PATHS.get_or_init(|| Default::default())
}

const NOTE: &str = "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n";
Expand Down Expand Up @@ -139,7 +141,7 @@ fn export_and_merge(
) -> Result<(), ExportError> {
use std::io::{Read, Write};

let mut lock = EXPORT_PATHS.lock().unwrap();
let lock = &mut get_export_paths().lock().unwrap();

let Some(entry) = lock.get_mut(&path) else {
// The file hasn't been written to yet, so it must be
Expand Down
2 changes: 1 addition & 1 deletion ts-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
//! [See CONTRIBUTING.md](https://github.com/Aleph-Alpha/ts-rs/blob/main/CONTRIBUTING.md)
//!
//! ## MSRV
//! The Minimum Supported Rust Version for this crate is 1.63.0
//! The Minimum Supported Rust Version for this crate is 1.74.1

use std::{
any::TypeId,
Expand Down
Loading