Remove the need for HostRef<Store> (#771)

* Remove the need for `HostRef<Store>`

This commit goes through the public API of the `wasmtime` crate and
removes the need for `HostRef<Store>`, as discussed in #708. This commit
is accompanied with a few changes:

* The `Store` type now also implements `Default`, creating a new
  `Engine` with default settings and returning that.

* The `Store` type now implements `Clone`, and is documented as being a
  "cheap clone" aka being reference counted. As before there is no
  supported way to create a deep clone of a `Store`.

* All APIs take/return `&Store` or `Store` instead of `HostRef<Store>`,
  and `HostRef<T>` is left as purely a detail of the C API.

* The `global_exports` function is tagged as `#[doc(hidden)]` for now
  while we await its removal.

* The `Store` type is not yet `Send` nor `Sync` due to the usage of
  `global_exports`, but it is intended to become so eventually.

* Touch up comments on some examples

* Run rustfmt
This commit is contained in:
Alex Crichton
2020-01-07 16:29:44 -06:00
committed by GitHub
parent 296ebc46fd
commit 045d6a7310
31 changed files with 163 additions and 155 deletions

View File

@@ -1,6 +1,6 @@
//! Translation of hello example
use anyhow::{ensure, format_err, Context as _, Result};
use anyhow::{ensure, Context as _, Result};
use std::rc::Rc;
use wasmtime::*;
@@ -15,11 +15,11 @@ impl Callable for HelloCallback {
}
fn main() -> Result<()> {
// Configure the initial compilation environment, creating more global
// structures such as an `Engine` and a `Store`.
// Configure the initial compilation environment, creating the global
// `Store` structure. Note that you can also tweak configuration settings
// with a `Config` and an `Engine` if desired.
println!("Initializing...");
let engine = Engine::default();
let store = HostRef::new(Store::new(&engine));
let store = Store::default();
// Next upload the `*.wasm` binary file, which in this case we're going to
// be parsing an inline text format into a binary.
@@ -59,10 +59,7 @@ fn main() -> Result<()> {
// And last but not least we can call it!
println!("Calling export...");
run_func
.borrow()
.call(&[])
.map_err(|e| format_err!("> Error calling function: {:?}", e))?;
run_func.borrow().call(&[])?;
println!("Done.");
Ok(())