Add docs.

This commit is contained in:
Sergey Pepyakin 2019-01-25 11:39:59 +01:00
parent cd9bcc073a
commit 1b8cf2705e
3 changed files with 46 additions and 0 deletions

View File

@ -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"]
extern crate proc_macro;

View File

@ -137,6 +137,8 @@ impl HostError {
/// Trait that allows to implement host functions.
///
/// You can use `wasmi-derive` or you can implement this trait manually.
///
/// # Examples
///
/// ```rust

View File

@ -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_derive;