From 1b8cf2705e277219d093b5820e39f84cd7834af1 Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Fri, 25 Jan 2019 11:39:59 +0100 Subject: [PATCH] Add docs. --- derive/src/lib.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ src/host.rs | 2 ++ tests/derives.rs | 2 ++ 3 files changed, 46 insertions(+) diff --git a/derive/src/lib.rs b/derive/src/lib.rs index c119dbc..cd5605f 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -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; diff --git a/src/host.rs b/src/host.rs index 3700fc7..e215a2f 100644 --- a/src/host.rs +++ b/src/host.rs @@ -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 diff --git a/tests/derives.rs b/tests/derives.rs index 1d93fcd..2f05f24 100644 --- a/tests/derives.rs +++ b/tests/derives.rs @@ -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;