From 4266926e9054f060360e60e054b32d2e1bcaeaa9 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 25 Sep 2019 12:35:35 -0700 Subject: [PATCH] Add ImportObject `maybe_with_namespace` example --- CHANGELOG.md | 1 + lib/runtime-core/src/import.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94677f085e8..f8e77c8226c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#833](https://github.com/wasmerio/wasmer/pull/833) Add doc example of using ImportObject's new `maybe_with_namespace` method - [#832](https://github.com/wasmerio/wasmer/pull/832) Delete unused runtime ABI - [#809](https://github.com/wasmerio/wasmer/pull/809) Fix bugs leading to panics in `LocalBacking`. - [#822](https://github.com/wasmerio/wasmer/pull/822) Update Cranelift fork version to `0.43.1` diff --git a/lib/runtime-core/src/import.rs b/lib/runtime-core/src/import.rs index 2cccf2325af..9d86205b156 100644 --- a/lib/runtime-core/src/import.rs +++ b/lib/runtime-core/src/import.rs @@ -124,6 +124,14 @@ impl ImportObject { } /// The same as `with_namespace` but takes a function that may fail + /// # Usage: + /// ``` + /// # use wasmer_runtime_core::import::{ImportObject, LikeNamespace}; + /// # use wasmer_runtime_core::export::Export; + /// fn get_export(imports: &ImportObject, namespace: &str, name: &str) -> Option { + /// imports.maybe_with_namespace(namespace, |ns| ns.get_export(name)) + /// } + /// ``` pub fn maybe_with_namespace(&self, namespace: &str, f: Func) -> Option where Func: FnOnce(&(dyn LikeNamespace + Send)) -> Option,