From 68a652ed2f51d366bb8033497e6dfe545895410e Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 23 Jul 2026 08:08:33 +0800 Subject: 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. --- src/config.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/config.rs (limited to 'src/config.rs') 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 = 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() +} -- cgit