doc(api) Improve the crate documentation.

This commit is contained in:
Ivan Enderlin
2021-07-23 16:14:44 +02:00
parent bc4ffb4311
commit 3239fe4f6d
2 changed files with 147 additions and 103 deletions

View File

@@ -1,64 +1,3 @@
#![doc(
html_logo_url = "https://github.com/wasmerio.png?size=200",
html_favicon_url = "https://wasmer.io/images/icons/favicon-32x32.png"
)]
#![deny(
missing_docs,
trivial_numeric_casts,
unused_extern_crates,
broken_intra_doc_links
)]
#![warn(unused_import_braces)]
#![cfg_attr(
feature = "cargo-clippy",
allow(clippy::new_without_default, clippy::vtable_address_comparisons)
)]
#![cfg_attr(
feature = "cargo-clippy",
warn(
clippy::float_arithmetic,
clippy::mut_mut,
clippy::nonminimal_bool,
clippy::map_unwrap_or,
clippy::print_stdout,
clippy::unicode_not_nfc,
clippy::use_self
)
)]
//! This crate contains the `wasmer-js` API. The `wasmer-js` API facilitates the efficient,
//! sandboxed execution of [WebAssembly (Wasm)][wasm] modules, leveraging on the same
//! API as the `wasmer` crate, but targeting Javascript.
//!
//! This crate uses the same WebAssembly engine as the Javascript VM where it's used.
//!
//! Here's an example of the `wasmer-js` API in action:
//! ```
//! #[wasm_bindgen]
//! pub extern fn do_add_one_in_wasmer() -> i32 {
//! let module_wat = r#"
//! (module
//! (type $t0 (func (param i32) (result i32)))
//! (func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
//! get_local $p0
//! i32.const 1
//! i32.add))
//! "#;
//! let store = Store::default();
//! let module = Module::new(&store, &module_wat).unwrap();
//! // The module doesn't import anything, so we create an empty import object.
//! let import_object = imports! {};
//! let instance = Instance::new(&module, &import_object).unwrap();
//! let add_one = instance.exports.get_function("add_one").unwrap();
//! let result = add_one.call(&[Value::I32(42)]).unwrap();
//! assert_eq!(result[0], Value::I32(43));
//! result[0].unwrap_i32()
//! }
//! ```
//!
//! For more examples of using the `wasmer` API, check out the
//! [wasmer examples][wasmer-examples].
#[cfg(all(feature = "std", feature = "core"))]
compile_error!(
"The `std` and `core` features are both enabled, which is an error. Please enable only once."