diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-23 08:08:33 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-23 14:01:45 +0800 |
| commit | 68a652ed2f51d366bb8033497e6dfe545895410e (patch) | |
| tree | d463833846248410733e196a0939c59cd67ca8a2 /src/config.rs | |
feat: scaffold crate structure and implement core macros
Add the project skeleton, LICENSE files, README, Makefile, doc
examples, and the initial implementation of `#[func]`, `invoke!`,
and `select!` procedural macros.
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..06aa088 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,38 @@ +use std::path::Path; +use std::sync::OnceLock; + +/// Returns the default feature name configured in the consuming crate's +/// `Cargo.toml` under `[package.metadata.might_be_async.default_feature_name]`. +/// +/// If the metadata key is absent or unreadable, falls back to `"async"`. +pub(crate) fn default_feature_name() -> &'static str { + static DEFAULT: OnceLock<String> = OnceLock::new(); + DEFAULT.get_or_init(read_default_feature_name) +} + +fn read_default_feature_name() -> String { + let manifest_dir = match std::env::var("CARGO_MANIFEST_DIR") { + Ok(dir) => dir, + Err(_) => return "async".to_string(), + }; + + let cargo_toml_path = Path::new(&manifest_dir).join("Cargo.toml"); + let content = match std::fs::read_to_string(cargo_toml_path) { + Ok(c) => c, + Err(_) => return "async".to_string(), + }; + + let value: toml::Value = match content.parse() { + Ok(v) => v, + Err(_) => return "async".to_string(), + }; + + value + .get("package") + .and_then(|p| p.get("metadata")) + .and_then(|m| m.get("might_be_async")) + .and_then(|a| a.get("default_feature_name")) + .and_then(|v| v.as_str()) + .unwrap_or("async") + .to_string() +} |
