@@ -63,7 +63,30 @@ use itertools::Itertools as _;
6363
6464use crate :: import:: ImportError ;
6565
66- pub use description:: { GENERATOR_KEY , USED_EXTENSIONS_KEY } ;
66+ // TODO centralise all core metadata keys in one place.
67+
68+ /// Key used to store the name of the generator that produced the envelope.
69+ pub const GENERATOR_KEY : & str = "core.generator" ;
70+ /// Key used to store the list of used extensions in the metadata of a HUGR.
71+ pub const USED_EXTENSIONS_KEY : & str = "core.used_extensions" ;
72+
73+ /// Get the name of the generator from the metadata of the HUGR modules.
74+ ///
75+ /// If multiple modules have different generators, a comma-separated list is returned in
76+ /// module order.
77+ /// If no generator is found, `None` is returned.
78+ pub fn get_generator < H : HugrView > ( modules : & [ H ] ) -> Option < String > {
79+ let generators: Vec < String > = modules
80+ . iter ( )
81+ . filter_map ( |hugr| hugr. get_metadata ( hugr. module_root ( ) , GENERATOR_KEY ) )
82+ . map ( format_generator)
83+ . collect ( ) ;
84+ if generators. is_empty ( ) {
85+ return None ;
86+ }
87+
88+ Some ( generators. join ( ", " ) )
89+ }
6790
6891/// Format a generator value from the metadata.
6992pub fn format_generator ( json_val : & serde_json:: Value ) -> String {
@@ -96,24 +119,6 @@ fn gen_str(generator: Option<&String>) -> String {
96119 }
97120}
98121
99- /// Get the name of the generator from the metadata of the HUGR modules.
100- ///
101- /// If multiple modules have different generators, a comma-separated list is returned in
102- /// module order.
103- /// If no generator is found, `None` is returned.
104- pub fn get_generator < H : HugrView > ( modules : & [ H ] ) -> Option < String > {
105- let generators: Vec < String > = modules
106- . iter ( )
107- . filter_map ( |hugr| hugr. get_metadata ( hugr. module_root ( ) , GENERATOR_KEY ) )
108- . map ( format_generator)
109- . collect ( ) ;
110- if generators. is_empty ( ) {
111- return None ;
112- }
113-
114- Some ( generators. join ( ", " ) )
115- }
116-
117122/// Wrap an error with a generator string.
118123#[ derive( Error , Debug ) ]
119124#[ deprecated( since = "0.24.1" , note = "Use PackageDesc instead" ) ]
0 commit comments