aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock5
-rw-r--r--Cargo.toml6
-rw-r--r--mingling/Cargo.toml5
-rw-r--r--mingling/src/features.rs11
-rw-r--r--mingling_core/Cargo.toml3
-rw-r--r--mingling_core/src/builds.rs3
-rw-r--r--mingling_macros/Cargo.toml1
-rw-r--r--mingling_pathf/Cargo.toml8
l---------mingling_pathf/LICENSE-APACHE1
l---------mingling_pathf/LICENSE-MIT1
-rw-r--r--mingling_pathf/README.md49
-rw-r--r--mingling_pathf/src/lib.rs0
l---------minglingmingling_pathfLICENSE-APACHE1
l---------minglingmingling_pathfLICENSE-MIT1
14 files changed, 92 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 62001a3..64d1da9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -421,6 +421,7 @@ dependencies = [
"just_fmt",
"just_template",
"log",
+ "mingling_pathf",
"ron",
"serde",
"serde_json",
@@ -439,6 +440,10 @@ dependencies = [
]
[[package]]
+name = "mingling_pathf"
+version = "0.2.0"
+
+[[package]]
name = "mio"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index acf96af..fedb095 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
-members = ["mingling", "mingling_core", "mingling_macros", "mling"]
+members = ["mingling", "mingling_core", "mingling_macros", "mingling_pathf", "mling"]
exclude = [
# README-Tests
"./temp/*",
@@ -16,6 +16,10 @@ exclude = [
]
[workspace.dependencies]
+mingling_core = { path = "mingling_core", default-features = false }
+mingling_macros = { path = "mingling_macros", default-features = false }
+mingling_pathf = { path = "mingling_pathf", default-features = false }
+
just_fmt = "0.1.2"
just_template = "0.1.3"
diff --git a/mingling/Cargo.toml b/mingling/Cargo.toml
index 0f2b37b..be223fe 100644
--- a/mingling/Cargo.toml
+++ b/mingling/Cargo.toml
@@ -44,6 +44,7 @@ dispatch_tree = ["mingling_core/dispatch_tree", "mingling_macros/dispatch_tree"]
repl = ["mingling_core/repl", "mingling_macros/repl"]
comp = ["mingling_core/comp", "mingling_macros/comp"]
parser = ["dep:size"]
+pathf = ["mingling_core/pathf", "mingling_macros/pathf"]
structural_renderer = [
"mingling_core/structural_renderer",
@@ -80,7 +81,7 @@ ron_serde_fmt = ["mingling_core/ron_serde_fmt"]
extra_macros = ["mingling_macros/extra_macros"]
[dependencies]
-mingling_core = { path = "../mingling_core", default-features = false }
-mingling_macros = { path = "../mingling_macros", default-features = false }
+mingling_core.workspace = true
+mingling_macros.workspace = true
serde = { workspace = true, optional = true }
size = { version = "0.5", optional = true }
diff --git a/mingling/src/features.rs b/mingling/src/features.rs
index 8f147fb..4d0c50b 100644
--- a/mingling/src/features.rs
+++ b/mingling/src/features.rs
@@ -130,6 +130,17 @@ pub const MINGLING_PARSER: bool = false;
#[cfg(feature = "parser")]
#[allow(unused)]
pub const MINGLING_PARSER: bool = true;
+/// Whether the `pathf` feature is enabled
+/// Current: `disabled`
+#[cfg(not(feature = "pathf"))]
+#[allow(unused)]
+pub const MINGLING_PATHF: bool = false;
+
+/// Whether the `pathf` feature is enabled
+/// Current: `enabled`
+#[cfg(feature = "pathf")]
+#[allow(unused)]
+pub const MINGLING_PATHF: bool = true;
/// Whether the `repl` feature is enabled
/// Current: `disabled`
#[cfg(not(feature = "repl"))]
diff --git a/mingling_core/Cargo.toml b/mingling_core/Cargo.toml
index b22a630..85afd55 100644
--- a/mingling_core/Cargo.toml
+++ b/mingling_core/Cargo.toml
@@ -28,8 +28,11 @@ repl = []
clap = []
comp = ["dep:just_template"]
debug = ["dep:log", "dep:env_logger"]
+pathf = ["dep:mingling_pathf"]
[dependencies]
+mingling_pathf = { workspace = true, optional = true }
+
just_fmt.workspace = true
# comp
diff --git a/mingling_core/src/builds.rs b/mingling_core/src/builds.rs
index 0123c82..51bafe6 100644
--- a/mingling_core/src/builds.rs
+++ b/mingling_core/src/builds.rs
@@ -1,3 +1,6 @@
#[doc(hidden)]
#[cfg(feature = "comp")]
pub mod comp;
+
+#[cfg(all(feature = "builds", feature = "pathf"))]
+pub use mingling_pathf::*;
diff --git a/mingling_macros/Cargo.toml b/mingling_macros/Cargo.toml
index db65381..66f654b 100644
--- a/mingling_macros/Cargo.toml
+++ b/mingling_macros/Cargo.toml
@@ -23,6 +23,7 @@ comp = []
dispatch_tree = []
structural_renderer = []
repl = []
+pathf = []
extra_macros = []
diff --git a/mingling_pathf/Cargo.toml b/mingling_pathf/Cargo.toml
new file mode 100644
index 0000000..90d94da
--- /dev/null
+++ b/mingling_pathf/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "mingling_pathf"
+version.workspace = true
+edition.workspace = true
+license.workspace = true
+repository.workspace = true
+
+[dependencies]
diff --git a/mingling_pathf/LICENSE-APACHE b/mingling_pathf/LICENSE-APACHE
new file mode 120000
index 0000000..965b606
--- /dev/null
+++ b/mingling_pathf/LICENSE-APACHE
@@ -0,0 +1 @@
+../LICENSE-APACHE \ No newline at end of file
diff --git a/mingling_pathf/LICENSE-MIT b/mingling_pathf/LICENSE-MIT
new file mode 120000
index 0000000..76219eb
--- /dev/null
+++ b/mingling_pathf/LICENSE-MIT
@@ -0,0 +1 @@
+../LICENSE-MIT \ No newline at end of file
diff --git a/mingling_pathf/README.md b/mingling_pathf/README.md
new file mode 100644
index 0000000..9706083
--- /dev/null
+++ b/mingling_pathf/README.md
@@ -0,0 +1,49 @@
+<p align="center">
+ <a href="https://github.com/mingling-rs/mingling">
+ <img alt="Mingling" src="https://github.com/mingling-rs/mingling/raw/main/docs/res/pixel_icon_core_1024.png" width="30%">
+ </a>
+</p>
+<h1 align="center">Mìng Lìng - Module PathFinder</h1>
+
+## Overview
+
+`mingling_pathf` provides the `pathf` feature for Mingling. It automatically analyzes the full module paths of all Mingling types in a crate at build-time (types defined via `pack!`, `#[derive(Groupped)]`, `#[chain]`, `#[renderer]`, etc.), and generates a mapping from type names to module paths for consumption by `gen_program!()` at compile-time.
+
+When enabled, `gen_program!()` uses full module paths for type references in the generated dispatch code (e.g., `downcast::<myapp::sub::ResultMyName>()`), eliminating the need to `use` all types in the module where `gen_program!()` is called. This allows for a more flexible module organization without the constraint of centralized `use` statements.
+
+## Usage
+
+Enable the `pathf` feature in `Cargo.toml`:
+
+```toml
+[dependencies.mingling]
+# Used to modify the generation behavior of `gen_program!`
+features = ["pathf"]
+
+[build-dependencies.mingling]
+# Provides the `analyze_and_build_type_mapping` function
+features = ["builds", "pathf"]
+```
+
+Create a `build.rs` in the project root:
+
+```rust
+fn main() {
+ mingling::build::analyze_and_build_type_mapping();
+}
+```
+
+> [!TIP]
+> If you already have a `build.rs` (e.g., using `builds` + `comp` features to generate completion scripts), simply add this function call.
+
+## How It Works
+
+1. **Build-time scanning**: `build.rs` traverses all `.rs` source files under `src/`, locating macro invocations such as `pack!`, `#[chain]`, `#[renderer]`, etc., via pattern matching.
+2. **Module inference**: The module path is inferred from the file's directory path (e.g., `src/app/sub.rs` → `app::sub`).
+3. **Reference tracking**: Following the chain of `mod use` re-exports (i.e., paths re-exported via `pub use` or `use`), the type name is resolved to the module path under which it is ultimately referenced.
+4. **Mapping output**: The mapping from type names to their final referenceable module paths is written to `$OUT_DIR/CRATE_NAME/type-mapping.rs`.
+5. **Compile-time consumption**: `gen_program!()` reads this mapping file and uses the full paths for downcasting in the generated dispatch code.
+
+## Constraints
+
+- Does not penetrate secondary indirect expansions of macros (i.e., cannot analyze Mingling type definitions indirectly generated by other macros).
diff --git a/mingling_pathf/src/lib.rs b/mingling_pathf/src/lib.rs
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mingling_pathf/src/lib.rs
diff --git a/minglingmingling_pathfLICENSE-APACHE b/minglingmingling_pathfLICENSE-APACHE
new file mode 120000
index 0000000..3be4b3c
--- /dev/null
+++ b/minglingmingling_pathfLICENSE-APACHE
@@ -0,0 +1 @@
+..LICENSE-APACHE \ No newline at end of file
diff --git a/minglingmingling_pathfLICENSE-MIT b/minglingmingling_pathfLICENSE-MIT
new file mode 120000
index 0000000..3d3baa8
--- /dev/null
+++ b/minglingmingling_pathfLICENSE-MIT
@@ -0,0 +1 @@
+..LICENSE-MIT \ No newline at end of file