Skip to content

Commit d6350c9

Browse files
committed
review suggestions
1 parent a8ca450 commit d6350c9

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

hugr-core/src/envelope.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ use itertools::Itertools as _;
6464
use crate::import::ImportError;
6565

6666
// TODO centralise all core metadata keys in one place.
67+
// https://github.com/CQCL/hugr/issues/2651
6768

6869
/// Key used to store the name of the generator that produced the envelope.
6970
pub const GENERATOR_KEY: &str = "core.generator";
@@ -392,7 +393,7 @@ pub enum EnvelopeError {
392393
flag_ids: Vec<usize>,
393394
},
394395
/// Error raised while checking for breaking extension version mismatch.
395-
// no longer used
396+
#[deprecated(since = "0.24.1")]
396397
#[error(transparent)]
397398
#[allow(deprecated)]
398399
ExtensionVersion {

hugr-core/src/envelope/description.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
7977
pub 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)]
94100
pub 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

105111
fn 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.
228226
pub struct Entrypoint {

0 commit comments

Comments
 (0)