Add docs.
This commit is contained in:
parent
cd9bcc073a
commit
1b8cf2705e
|
@ -1,3 +1,45 @@
|
||||||
|
//! A derive macro for generation of simple `Externals`.
|
||||||
|
//!
|
||||||
|
//! ```nocompile
|
||||||
|
//! #// no compile because we can't depend on wasmi here, or otherwise it will be a circular dependency.
|
||||||
|
//! extern crate wasmi;
|
||||||
|
//! extern crate wasmi_derive;
|
||||||
|
//!
|
||||||
|
//! use std::fmt;
|
||||||
|
//! use wasmi::HostError;
|
||||||
|
//! use wasmi_derive::derive_externals;
|
||||||
|
//!
|
||||||
|
//! #[derive(Debug)]
|
||||||
|
//! struct NoInfoError;
|
||||||
|
//! impl HostError for NoInfoError {}
|
||||||
|
//! impl fmt::Display for NoInfoError {
|
||||||
|
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
//! write!(f, "NoInfoError")
|
||||||
|
//! }
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! struct NonStaticExternals<'a> {
|
||||||
|
//! state: &'a mut usize,
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! #[derive_externals]
|
||||||
|
//! impl<'a> NonStaticExternals<'a> {
|
||||||
|
//! pub fn hello(&self, a: u32, b: u32) -> u32 {
|
||||||
|
//! a + b
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! pub fn increment(&mut self) {
|
||||||
|
//! *self.state += 1;
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! pub fn traps(&self) -> Result<(), NoInfoError> {
|
||||||
|
//! Err(NoInfoError)
|
||||||
|
//! }
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
|
||||||
|
// We reached the `recursion_limit` in quote macro.
|
||||||
#![recursion_limit = "128"]
|
#![recursion_limit = "128"]
|
||||||
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
|
@ -137,6 +137,8 @@ impl HostError {
|
||||||
|
|
||||||
/// Trait that allows to implement host functions.
|
/// Trait that allows to implement host functions.
|
||||||
///
|
///
|
||||||
|
/// You can use `wasmi-derive` or you can implement this trait manually.
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// If you are to update this code, make sure you update the example in `wasmi-derive`.
|
||||||
|
|
||||||
extern crate wasmi;
|
extern crate wasmi;
|
||||||
extern crate wasmi_derive;
|
extern crate wasmi_derive;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue