Skip to content

Commit f51da3c

Browse files
committed
review suggestions
1 parent 9356a6d commit f51da3c

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
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";
@@ -386,7 +387,7 @@ pub enum EnvelopeError {
386387
flag_ids: Vec<usize>,
387388
},
388389
/// Error raised while checking for breaking extension version mismatch.
389-
// no longer used
390+
#[deprecated(since = "0.24.1")]
390391
#[error(transparent)]
391392
#[allow(deprecated)]
392393
ExtensionVersion {

hugr-core/src/envelope/description.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,36 @@ mod wrapper {
9494
pub use wrapper::DescribedPackage;
9595
pub(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)]
110118
pub 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

121129
fn 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.
244244
pub struct Entrypoint {

0 commit comments

Comments
 (0)