@@ -94,28 +94,36 @@ mod wrapper {
9494pub use wrapper:: DescribedPackage ;
9595pub ( crate ) use wrapper:: { Described , ModuleDescResult , PackageDescResult , transpose} ;
9696
97- type PartialVec < T > = Vec < Option < T > > ;
98- fn set_partial_len < T : Clone > ( vec : & mut PartialVec < T > , n : usize ) {
97+ type OptionVec < T > = Vec < Option < T > > ;
98+ fn set_option_vec_len < T : Clone > ( vec : & mut OptionVec < T > , n : usize ) {
9999 vec. resize ( n, None ) ;
100100}
101- fn set_partial_index < T : Clone > ( vec : & mut PartialVec < T > , index : usize , value : T ) {
101+ fn set_option_vec_index < T : Clone > ( vec : & mut OptionVec < T > , index : usize , value : T ) {
102102 if index >= vec. len ( ) {
103- set_partial_len ( vec, index + 1 ) ;
103+ set_option_vec_len ( vec, index + 1 ) ;
104104 }
105105 vec[ index] = Some ( value) ;
106106}
107107
108+ fn extend_option_vec < T : Clone > ( vec : & mut Option < Vec < T > > , items : impl IntoIterator < Item = T > ) {
109+ if let Some ( existing) = vec {
110+ existing. extend ( items) ;
111+ } else {
112+ vec. replace ( items. into_iter ( ) . collect ( ) ) ;
113+ }
114+ }
115+
108116/// High-level description of a HUGR package.
109117#[ derive( Debug , Clone , PartialEq , Default , serde:: Serialize ) ]
110118pub struct PackageDesc {
111119 /// Envelope header information.
112120 #[ serde( serialize_with = "header_serialize" ) ]
113121 pub header : EnvelopeHeader ,
114122 /// Description of the modules in the package.
115- pub modules : PartialVec < ModuleDesc > ,
123+ pub modules : OptionVec < ModuleDesc > ,
116124 /// Description of the extensions in the package.
117125 #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
118- pub packaged_extensions : PartialVec < ExtensionDesc > ,
126+ pub packaged_extensions : OptionVec < ExtensionDesc > ,
119127}
120128
121129fn header_serialize < S > ( header : & EnvelopeHeader , serializer : S ) -> Result < S :: Ok , S :: Error >
@@ -136,7 +144,7 @@ impl PackageDesc {
136144
137145 /// Sets the number of modules in the package.
138146 pub ( crate ) fn set_n_modules ( & mut self , n : usize ) {
139- set_partial_len ( & mut self . modules , n) ;
147+ set_option_vec_len ( & mut self . modules , n) ;
140148 }
141149
142150 /// Returns the package header.
@@ -151,12 +159,12 @@ impl PackageDesc {
151159
152160 /// Sets a module description at the specified index.
153161 pub ( crate ) fn set_module ( & mut self , index : usize , module : impl Into < ModuleDesc > ) {
154- set_partial_index ( & mut self . modules , index, module. into ( ) ) ;
162+ set_option_vec_index ( & mut self . modules , index, module. into ( ) ) ;
155163 }
156164
157165 /// Sets a packaged extension description at the specified index.
158166 pub ( crate ) fn set_packaged_extension ( & mut self , index : usize , ext : impl Into < ExtensionDesc > ) {
159- set_partial_index ( & mut self . packaged_extensions , index, ext. into ( ) ) ;
167+ set_option_vec_index ( & mut self . packaged_extensions , index, ext. into ( ) ) ;
160168 }
161169
162170 /// Returns the number of packaged extensions in the package.
@@ -231,14 +239,6 @@ impl<E: AsRef<crate::Extension>> From<&E> for ExtensionDesc {
231239 }
232240}
233241
234- fn extend_option_vec < T : Clone > ( vec : & mut Option < Vec < T > > , items : impl IntoIterator < Item = T > ) {
235- if let Some ( existing) = vec {
236- existing. extend ( items) ;
237- } else {
238- vec. replace ( items. into_iter ( ) . collect ( ) ) ;
239- }
240- }
241-
242242#[ derive( Debug , Clone , PartialEq , serde:: Serialize ) ]
243243/// Description of the entrypoint of a module.
244244pub struct Entrypoint {
0 commit comments