Skip to content

Commit

Permalink
Revise examples to avoid using nth.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Apr 18, 2020
1 parent cca2031 commit d1e639f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions crates/api/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,15 @@ impl Module {
/// let module = Module::new(&store, wat)?;
/// assert_eq!(module.exports().len(), 2);
///
/// let foo = module.exports().next().unwrap();
/// let mut exports = module.exports();
/// let foo = exports.next().unwrap();
/// assert_eq!(foo.name, "foo");
/// match foo.ty {
/// ExternType::Func(_) => { /* ... */ }
/// _ => panic!("unexpected export type!"),
/// }
///
/// let memory = module.exports().nth(1).unwrap();
/// let memory = exports.next().unwrap();
/// assert_eq!(memory.name, "memory");
/// match memory.ty {
/// ExternType::Memory(_) => { /* ... */ }
Expand Down
5 changes: 3 additions & 2 deletions tests/all/traps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,15 @@ fn rust_panic_import() -> Result<()> {
Func::wrap(&store, || panic!("this is another panic")).into(),
],
)?;
let func = instance.exports().next().unwrap().into_func().unwrap();
let mut exports = instance.exports();
let func = exports.next().unwrap().into_func().unwrap();
let err = panic::catch_unwind(AssertUnwindSafe(|| {
drop(func.call(&[]));
}))
.unwrap_err();
assert_eq!(err.downcast_ref::<&'static str>(), Some(&"this is a panic"));

let func = instance.exports().nth(1).unwrap().into_func().unwrap();
let func = exports.next().unwrap().into_func().unwrap();
let err = panic::catch_unwind(AssertUnwindSafe(|| {
drop(func.call(&[]));
}))
Expand Down

0 comments on commit d1e639f

Please sign in to comment.