@@ -73,33 +73,39 @@ mod wrapper {
7373
7474 /// Package wrapped with its description.
7575 pub type DescribedPackage = Described < crate :: package:: Package , PackageDesc > ;
76-
77-
7876}
7977pub use wrapper:: { Described , DescribedPackage , ModuleDescResult , PackageDescResult } ;
8078
81- type PartialVec < T > = Vec < Option < T > > ;
82- fn set_partial_len < T : Clone > ( vec : & mut PartialVec < T > , n : usize ) {
79+ type OptionVec < T > = Vec < Option < T > > ;
80+ fn set_option_vec_len < T : Clone > ( vec : & mut OptionVec < T > , n : usize ) {
8381 vec. resize ( n, None ) ;
8482}
85- fn set_partial_index < T : Clone > ( vec : & mut PartialVec < T > , index : usize , value : T ) {
83+ fn set_option_vec_index < T : Clone > ( vec : & mut OptionVec < T > , index : usize , value : T ) {
8684 if index >= vec. len ( ) {
87- set_partial_len ( vec, index + 1 ) ;
85+ set_option_vec_len ( vec, index + 1 ) ;
8886 }
8987 vec[ index] = Some ( value) ;
9088}
9189
90+ fn extend_option_vec < T : Clone > ( vec : & mut Option < Vec < T > > , items : impl IntoIterator < Item = T > ) {
91+ if let Some ( existing) = vec {
92+ existing. extend ( items) ;
93+ } else {
94+ vec. replace ( items. into_iter ( ) . collect ( ) ) ;
95+ }
96+ }
97+
9298/// High-level description of a HUGR package.
9399#[ derive( Debug , Clone , PartialEq , Default , serde:: Serialize ) ]
94100pub struct PackageDesc {
95101 /// Envelope header information.
96102 #[ serde( serialize_with = "header_serialize" ) ]
97103 pub header : EnvelopeHeader ,
98104 /// Description of the modules in the package.
99- pub modules : PartialVec < ModuleDesc > ,
105+ pub modules : OptionVec < ModuleDesc > ,
100106 /// Description of the extensions in the package.
101107 #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
102- pub packaged_extensions : PartialVec < ExtensionDesc > ,
108+ pub packaged_extensions : OptionVec < ExtensionDesc > ,
103109}
104110
105111fn header_serialize < S > ( header : & EnvelopeHeader , serializer : S ) -> Result < S :: Ok , S :: Error >
@@ -120,7 +126,7 @@ impl PackageDesc {
120126
121127 /// Sets the number of modules in the package.
122128 pub ( crate ) fn set_n_modules ( & mut self , n : usize ) {
123- set_partial_len ( & mut self . modules , n) ;
129+ set_option_vec_len ( & mut self . modules , n) ;
124130 }
125131
126132 /// Returns the package header.
@@ -135,12 +141,12 @@ impl PackageDesc {
135141
136142 /// Sets a module description at the specified index.
137143 pub ( crate ) fn set_module ( & mut self , index : usize , module : impl Into < ModuleDesc > ) {
138- set_partial_index ( & mut self . modules , index, module. into ( ) ) ;
144+ set_option_vec_index ( & mut self . modules , index, module. into ( ) ) ;
139145 }
140146
141147 /// Sets a packaged extension description at the specified index.
142148 pub ( crate ) fn set_packaged_extension ( & mut self , index : usize , ext : impl Into < ExtensionDesc > ) {
143- set_partial_index ( & mut self . packaged_extensions , index, ext. into ( ) ) ;
149+ set_option_vec_index ( & mut self . packaged_extensions , index, ext. into ( ) ) ;
144150 }
145151
146152 /// Returns the number of packaged extensions in the package.
@@ -215,14 +221,6 @@ impl<E: AsRef<crate::Extension>> From<&E> for ExtensionDesc {
215221 }
216222}
217223
218- fn extend_option_vec < T : Clone > ( vec : & mut Option < Vec < T > > , items : impl IntoIterator < Item = T > ) {
219- if let Some ( existing) = vec {
220- existing. extend ( items) ;
221- } else {
222- vec. replace ( items. into_iter ( ) . collect ( ) ) ;
223- }
224- }
225-
226224#[ derive( Debug , Clone , PartialEq , serde:: Serialize ) ]
227225/// Description of the entrypoint of a module.
228226pub struct Entrypoint {
0 commit comments