mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 05:38:19 +00:00
doc(api) Improve the crate documentation.
This commit is contained in:
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user