Add ImportObject maybe_with_namespace example

This commit is contained in:
Mark McCaskey
2019-09-25 12:35:35 -07:00
parent cda35afce0
commit 4266926e90
2 changed files with 9 additions and 0 deletions

View File

@ -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`

View File

@ -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<Export> {
/// imports.maybe_with_namespace(namespace, |ns| ns.get_export(name))
/// }
/// ```
pub fn maybe_with_namespace<Func, InnerRet>(&self, namespace: &str, f: Func) -> Option<InnerRet>
where
Func: FnOnce(&(dyn LikeNamespace + Send)) -> Option<InnerRet>,