Skip to content

Commit 28454a4

Browse files
committed
Use ExactSizeIterator to avoid needing separate num_* methods.
1 parent 840fbbb commit 28454a4

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

crates/api/src/instance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ impl Instance {
126126
}
127127
}
128128

129-
if imports.len() != module.num_imports() {
129+
if imports.len() != module.imports().len() {
130130
bail!(
131131
"wrong number of imports provided, {} != {}",
132132
imports.len(),
133-
module.num_imports()
133+
module.imports().len()
134134
);
135135
}
136136

@@ -164,7 +164,7 @@ impl Instance {
164164
/// information about the export itself. The list returned here maps 1:1 with
165165
/// the list that [`Module::exports`] returns, and [`ExportType`](crate::ExportType)
166166
/// contains the name of each export.
167-
pub fn exports<'me>(&'me self) -> impl Iterator<Item = Export> + 'me {
167+
pub fn exports<'me>(&'me self) -> impl ExactSizeIterator<Item = Export> + 'me {
168168
let instance_handle = &self.instance_handle;
169169
let store = self.module.store();
170170
self.instance_handle

crates/api/src/module.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl Module {
376376
/// # fn main() -> anyhow::Result<()> {
377377
/// # let store = Store::default();
378378
/// let module = Module::new(&store, "(module)")?;
379-
/// assert_eq!(module.num_imports(), 0);
379+
/// assert_eq!(module.imports().len(), 0);
380380
/// # Ok(())
381381
/// # }
382382
/// ```
@@ -393,7 +393,7 @@ impl Module {
393393
/// )
394394
/// "#;
395395
/// let module = Module::new(&store, wat)?;
396-
/// assert_eq!(module.num_imports(), 1);
396+
/// assert_eq!(module.imports().len(), 1);
397397
/// let import = module.imports().next().unwrap();
398398
/// assert_eq!(import.module, "host");
399399
/// assert_eq!(import.name, "foo");
@@ -404,7 +404,7 @@ impl Module {
404404
/// # Ok(())
405405
/// # }
406406
/// ```
407-
pub fn imports<'me>(&'me self) -> impl Iterator<Item = ImportType> + 'me {
407+
pub fn imports<'me>(&'me self) -> impl ExactSizeIterator<Item = ImportType> + 'me {
408408
let module = self.inner.compiled.module_ref();
409409
module
410410
.imports
@@ -419,11 +419,6 @@ impl Module {
419419
})
420420
}
421421

422-
/// Return the number of imports in this module.
423-
pub fn num_imports(&self) -> usize {
424-
self.inner.compiled.module_ref().imports.len()
425-
}
426-
427422
/// Returns the list of exports that this [`Module`] has and will be
428423
/// available after instantiation.
429424
///
@@ -459,7 +454,7 @@ impl Module {
459454
/// )
460455
/// "#;
461456
/// let module = Module::new(&store, wat)?;
462-
/// assert_eq!(module.num_exports(), 2);
457+
/// assert_eq!(module.exports().len(), 2);
463458
///
464459
/// let foo = module.exports().next().unwrap();
465460
/// assert_eq!(foo.name, "foo");
@@ -477,7 +472,7 @@ impl Module {
477472
/// # Ok(())
478473
/// # }
479474
/// ```
480-
pub fn exports<'me>(&'me self) -> impl Iterator<Item = ExportType> + 'me {
475+
pub fn exports<'me>(&'me self) -> impl ExactSizeIterator<Item = ExportType> + 'me {
481476
let module = self.inner.compiled.module_ref();
482477
module.exports.iter().map(move |(name, entity_index)| {
483478
let r#type = entity_type(entity_index, module);
@@ -488,11 +483,6 @@ impl Module {
488483
})
489484
}
490485

491-
/// Return the number of exports in this module.
492-
pub fn num_exports(&self) -> usize {
493-
self.inner.compiled.module_ref().exports.len()
494-
}
495-
496486
/// Returns the [`Store`] that this [`Module`] was compiled into.
497487
pub fn store(&self) -> &Store {
498488
&self.inner.store

0 commit comments

Comments
 (0)