macros: Remove dependency to once_cell

Use OnceLock from std instead.
This commit is contained in:
Kévin Commaille 2024-11-27 18:01:14 +01:00 committed by strawberry
parent d82e2a02d5
commit f2b58e5e07
2 changed files with 29 additions and 27 deletions

View File

@ -22,7 +22,6 @@ __internal_macro_expand = ["syn/visit-mut"]
[dependencies]
cfg-if = "1.0.0"
once_cell = "1.13.0"
proc-macro-crate = "3.1.0"
proc-macro2 = "1.0.24"
quote = "1.0.8"

View File

@ -1,8 +1,7 @@
//! Methods and types for generating API endpoints.
use std::{env, fs, path::Path};
use std::{env, fs, path::Path, sync::OnceLock};
use once_cell::sync::Lazy;
use proc_macro2::Span;
use serde::{de::IgnoredAny, Deserialize};
@ -29,9 +28,13 @@ fn ensure_feature_presence() -> Option<&'static syn::Error> {
server: Option<IgnoredAny>,
}
static RESULT: Lazy<Result<(), syn::Error>> = Lazy::new(|| {
let manifest_dir = env::var("CARGO_MANIFEST_DIR")
.map_err(|_| syn::Error::new(Span::call_site(), "Failed to read CARGO_MANIFEST_DIR"))?;
static RESULT: OnceLock<Result<(), syn::Error>> = OnceLock::new();
RESULT
.get_or_init(|| {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").map_err(|_| {
syn::Error::new(Span::call_site(), "Failed to read CARGO_MANIFEST_DIR")
})?;
let manifest_file = Path::new(&manifest_dir).join("Cargo.toml");
let manifest_bytes = fs::read_to_string(manifest_file)
@ -59,7 +62,7 @@ fn ensure_feature_presence() -> Option<&'static syn::Error> {
}
Ok(())
});
RESULT.as_ref().err()
})
.as_ref()
.err()
}