Skip to content

Commit e91bac3

Browse files
committed
Add missings docs and #[warn(missing_docs)]
1 parent 2f31243 commit e91bac3

10 files changed

+48
-24
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ wasm3 = { git = "https://github.com/Veykril/wasm3-rs.git" }
1818
A simple [example](./examples/call_wasm.rs) that loads a wasm module and executes an exported function to add two `i64`s together.
1919

2020
```rust
21-
use wasm3::environment::Environment;
22-
use wasm3::module::Module;
21+
use wasm3::Environment;
22+
use wasm3::Module;
2323

2424
fn main() {
2525
let env = Environment::new().expect("Unable to create environment");

Diff for: examples/call_wasm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use wasm3::environment::Environment;
2-
use wasm3::module::Module;
1+
use wasm3::Environment;
2+
use wasm3::Module;
33

44
fn main() {
55
let env = Environment::new().expect("Unable to create environment");

Diff for: examples/wasm_link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use wasm3::environment::Environment;
2-
use wasm3::module::Module;
1+
use wasm3::Environment;
2+
use wasm3::Module;
33

44
const MILLIS: u64 = 500_000;
55

Diff for: examples/wasm_link_closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use wasm3::environment::Environment;
2-
use wasm3::module::Module;
1+
use wasm3::Environment;
2+
use wasm3::Module;
33

44
const MILLIS: u64 = 500_000;
55

Diff for: examples/wasm_print.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use wasm3::environment::Environment;
2-
use wasm3::module::Module;
1+
use wasm3::Environment;
2+
use wasm3::Module;
33

44
#[cfg(feature = "wasi")]
55
fn main() {

Diff for: src/environment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl Drop for DropEnvironment {
1414
}
1515
}
1616

17-
/// An environment is required to construct [`Runtime`]s from. It currently serves no real purpose.
17+
/// An environment is required to construct [`Runtime`]s from. It currently serves no purpose but may in the future.
1818
#[derive(Debug, Clone)]
1919
pub struct Environment(Rc<DropEnvironment>);
2020

Diff for: src/error.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
1+
//! Error related functionality of wasm3.
12
use core::cmp;
23
use core::fmt;
34

45
use crate::utils::cstr_to_str;
56

7+
/// Result alias that uses [`Error`].
68
pub type Result<T> = core::result::Result<T, Error>;
7-
9+
/// Result alias that uses [`Trap`].
810
pub type TrappedResult<T> = core::result::Result<T, Trap>;
11+
12+
/// A wasm trap.
913
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1014
pub enum Trap {
15+
/// Out of bounds memory access
1116
OutOfBoundsMemoryAccess,
17+
/// Division by zero
1218
DivisionByZero,
19+
/// Integer overflow
1320
IntegerOverflow,
21+
/// Integer conversion
1422
IntegerConversion,
23+
/// Indirect call type mismatch
1524
IndirectCallTypeMismatch,
25+
/// Table index out of range
1626
TableIndexOutOfRange,
27+
/// Exit
1728
Exit,
29+
/// Abort
1830
Abort,
31+
/// Unreachable
1932
Unreachable,
33+
/// Stack overflow
2034
StackOverflow,
2135
}
2236

2337
impl Trap {
38+
#[doc(hidden)]
2439
pub fn as_ptr(self) -> ffi::M3Result {
2540
unsafe {
2641
match self {
@@ -53,10 +68,12 @@ impl fmt::Display for Trap {
5368
}
5469
}
5570

71+
/// Error returned by wasm3.
5672
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
5773
pub struct Wasm3Error(*const cty::c_char);
5874

5975
impl Wasm3Error {
76+
/// Check whether this error is the specified trap.
6077
pub fn is_trap(self, trap: Trap) -> bool {
6178
trap.as_ptr() == self.0
6279
}

Diff for: src/function.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::wasm3_priv;
1010
use crate::{WasmArgs, WasmType};
1111

1212
// redefine of ffi::RawCall without the Option<T> around it
13+
/// Type of a raw host function for wasm3.
1314
pub type RawCall = unsafe extern "C" fn(
1415
runtime: ffi::IM3Runtime,
1516
_sp: ffi::m3stack_t,
@@ -19,7 +20,7 @@ pub type RawCall = unsafe extern "C" fn(
1920
pub(crate) type NNM3Function = NonNull<ffi::M3Function>;
2021

2122
/// A callable wasm3 function.
22-
/// This has a generic `call` function for up to 26 parameters.
23+
/// This has a generic `call` function for up to 26 parameters emulating an overloading behaviour without having to resort to tuples.
2324
/// These are hidden to not pollute the documentation.
2425
#[derive(Debug, Copy, Clone)]
2526
pub struct Function<'rt, ARGS, RET> {

Diff for: src/lib.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
2+
#![warn(missing_docs)]
23
#![warn(clippy::all)]
34
#![allow(clippy::new_without_default, clippy::match_bool)]
5+
//! A rust wrapper for [WASM3](https://github.com/wasm3/wasm3).
46
57
extern crate alloc;
68

7-
pub mod environment;
89
pub mod error;
9-
pub mod function;
10-
pub mod module;
11-
pub mod runtime;
1210

13-
mod ty;
14-
pub use self::ty::{WasmArg, WasmArgs, WasmType};
11+
mod environment;
12+
pub use self::environment::Environment;
13+
mod function;
14+
pub use self::function::{Function, RawCall};
1515
mod macros;
1616
pub use self::macros::*;
17+
mod module;
18+
pub use self::module::{Module, ParsedModule};
19+
mod runtime;
20+
pub use self::runtime::Runtime;
21+
mod ty;
22+
pub use self::ty::{WasmArg, WasmArgs, WasmType};
1723
mod utils;
18-
pub(crate) mod wasm3_priv;
19-
2024
pub use ffi as wasm3_sys;
25+
26+
pub(crate) mod wasm3_priv;

Diff for: tests/rust_call_wasm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use wasm3::environment::Environment;
2-
use wasm3::module::Module;
3-
use wasm3::runtime::Runtime;
1+
use wasm3::Environment;
2+
use wasm3::Module;
3+
use wasm3::Runtime;
44

55
fn runtime() -> Runtime {
66
Environment::new()

0 commit comments

Comments
 (0)