From 4588e17f7ddacd8391a5c881a209735e08d48797 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 4 Aug 2026 13:26:48 +0800 Subject: feat: add entry metadata system with compile-time typed values Add `Metadata` trait and `#[metadata(Entry)]` attribute macro to attach arbitrary, compile-time-typed metadata to entries. Implement `ProgramCollect::get_metadata()` for runtime retrieval, backed by a global registry populated by `register_metadata!`. Extend `pathf` with `MetadataPattern` to resolve metadata types across modules at build time. Add two examples demonstrating metadata usage with and without pathf integration. --- mingling_pathf/test/src/lib.rs | 33 ++++++++++++++++++ .../test/src/test_files/test_metadata.rs | 40 ++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 mingling_pathf/test/src/test_files/test_metadata.rs (limited to 'mingling_pathf/test') diff --git a/mingling_pathf/test/src/lib.rs b/mingling_pathf/test/src/lib.rs index 7e7cbd5..8b13e52 100644 --- a/mingling_pathf/test/src/lib.rs +++ b/mingling_pathf/test/src/lib.rs @@ -387,3 +387,36 @@ fn test_dispatcher_clap_dispatch_tree() { assert!(r2.contains("::sub::__internal_dispatcher_delete")); assert!(r2.contains("::sub::__internal_dispatcher_helpcmd")); } + +#[test] +fn test_metadata_analyze() { + let analyzer = mingling_pathf::pattern_analyzer::init(); + let file = current_dir() + .unwrap() + .join("src/test_files/test_metadata.rs"); + + let r = analyzer.analyze_file(file).unwrap(); + let required: Vec<&str> = vec![ + // Root: BindType + DataType pairs + "::EntryGreet1", + "::Description1", + "::EntryGreet2", + "::Description2", + "::EntryGreet3", + "::LocalType3", + "::EntryGreet4", + "::std::collections::HashMap", + "::EntryGreet5", + "::Qualified5", + // Sub: BindType + DataType pairs + "::sub::EntrySub1", + "::sub::SubType1", + "::sub::EntrySub2", + "::sub::SubType2", + ]; + + assert_eq!(r.len(), required.len()); + for entry in &required { + assert!(r.contains(*entry), "Result should contain: {entry}"); + } +} diff --git a/mingling_pathf/test/src/test_files/test_metadata.rs b/mingling_pathf/test/src/test_files/test_metadata.rs new file mode 100644 index 0000000..52a2d4c --- /dev/null +++ b/mingling_pathf/test/src/test_files/test_metadata.rs @@ -0,0 +1,40 @@ +// Root-level metadata functions +#[mingling::macros::metadata(EntryGreet1)] +pub fn get_desc1() -> Description1 { + Description1 {} +} + +#[metadata(EntryGreet2)] +fn get_desc2() -> Description2 { + Description2 {} +} + +// Local DataType (defined in-crate) + foreign DataType +#[metadata(EntryGreet3)] +pub fn get_desc3() -> LocalType3 { + LocalType3 {} +} + +use std::collections::HashMap; + +#[metadata(EntryGreet4)] +fn get_desc4() -> HashMap { + HashMap::new() +} + +#[metadata(EntryGreet5)] +pub fn get_desc5() -> crate::fully::Qualified5 { + crate::fully::Qualified5 {} +} + +pub mod sub { + #[mingling::macros::metadata(EntrySub1)] + pub fn get_sub1() -> SubType1 { + SubType1 {} + } + + #[metadata(EntrySub2)] + fn get_sub2() -> SubType2 { + SubType2 {} + } +} -- cgit