macros: Remove dependency to once_cell
Use OnceLock from std instead.
This commit is contained in:
parent
d82e2a02d5
commit
f2b58e5e07
@ -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"
|
||||
|
@ -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,37 +28,41 @@ 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();
|
||||
|
||||
let manifest_file = Path::new(&manifest_dir).join("Cargo.toml");
|
||||
let manifest_bytes = fs::read_to_string(manifest_file)
|
||||
.map_err(|_| syn::Error::new(Span::call_site(), "Failed to read Cargo.toml"))?;
|
||||
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_parsed: CargoToml = toml::from_str(&manifest_bytes)
|
||||
.map_err(|_| syn::Error::new(Span::call_site(), "Failed to parse Cargo.toml"))?;
|
||||
let manifest_file = Path::new(&manifest_dir).join("Cargo.toml");
|
||||
let manifest_bytes = fs::read_to_string(manifest_file)
|
||||
.map_err(|_| syn::Error::new(Span::call_site(), "Failed to read Cargo.toml"))?;
|
||||
|
||||
if manifest_parsed.features.client.is_none() {
|
||||
return Err(syn::Error::new(
|
||||
Span::call_site(),
|
||||
"This crate doesn't define a `client` feature in its `Cargo.toml`.\n\
|
||||
let manifest_parsed: CargoToml = toml::from_str(&manifest_bytes)
|
||||
.map_err(|_| syn::Error::new(Span::call_site(), "Failed to parse Cargo.toml"))?;
|
||||
|
||||
if manifest_parsed.features.client.is_none() {
|
||||
return Err(syn::Error::new(
|
||||
Span::call_site(),
|
||||
"This crate doesn't define a `client` feature in its `Cargo.toml`.\n\
|
||||
Please add a `client` feature such that generated `OutgoingRequest` and \
|
||||
`IncomingResponse` implementations can be enabled.",
|
||||
));
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
if manifest_parsed.features.server.is_none() {
|
||||
return Err(syn::Error::new(
|
||||
Span::call_site(),
|
||||
"This crate doesn't define a `server` feature in its `Cargo.toml`.\n\
|
||||
if manifest_parsed.features.server.is_none() {
|
||||
return Err(syn::Error::new(
|
||||
Span::call_site(),
|
||||
"This crate doesn't define a `server` feature in its `Cargo.toml`.\n\
|
||||
Please add a `server` feature such that generated `IncomingRequest` and \
|
||||
`OutgoingResponse` implementations can be enabled.",
|
||||
));
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
});
|
||||
|
||||
RESULT.as_ref().err()
|
||||
Ok(())
|
||||
})
|
||||
.as_ref()
|
||||
.err()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user