Skip to content

Commit 7c1c0b2

Browse files
authored
Merge pull request #62 from ewasm/doc-cleanup
Clean up documentation (rustdoc)
2 parents a187ff3 + f41a0f0 commit 7c1c0b2

File tree

8 files changed

+71
-34
lines changed

8 files changed

+71
-34
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@ Add the dependency, as usual:
1212
[dependencies]
1313
ewasm-api = "0.8"
1414
```
15+
16+
In your project, include the prelude:
1517
```rust
16-
extern crate ewasm_api;
18+
use ewasm_api::prelude::*;
1719
```
1820

21+
Other modules are available as well, outside of the prelude. Refer to the documentation for more info.
22+
23+
`ewasm-rust-api` builds with various feature sets:
24+
- `default`: Builds with `wee_alloc` as the global allocator and with the Rust standard library.
25+
- `qimalloc`: Builds with [qimalloc](https://github.com/wasmx/qimalloc) as the global allocator.
26+
- `debug`: Exposes the debugging interface.
27+
- `experimental`: Exposes the experimental bignum system library API.
28+
1929
Further documentation is available [here](https://docs.rs/ewasm_api/).
2030

2131
## Author(s)

src/bignum.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
//! The bignum system library.
2+
use crate::types::Uint256;
23

3-
use super::*;
4-
4+
/// The low-level interface to the system library. Use the wrapper functions unless you know what
5+
/// you're doing.
56
pub mod native {
67
extern "C" {
78
pub fn bignum_mul256(a: *const u32, b: *const u32, ret: *const u32);
89
pub fn bignum_umulmod256(a: *const u32, b: *const u32, modulo: *const u32, ret: *const u32);
910
}
1011
}
1112

13+
/// Unsigned 256-bit multiplication.
1214
pub fn mul256(a: &Uint256, b: &Uint256) -> Uint256 {
1315
let mut ret = Uint256::default();
1416

@@ -23,6 +25,7 @@ pub fn mul256(a: &Uint256, b: &Uint256) -> Uint256 {
2325
ret
2426
}
2527

28+
/// Unsigned 256-bit multiplication modulo n.
2629
pub fn umulmod256(a: &Uint256, b: &Uint256, modulo: &Uint256) -> Uint256 {
2730
let mut ret = Uint256::default();
2831

src/convert.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Basic type conversion traits. Unlike the native standard library, `U: From<T>` does not yet
2+
//! imply `T: Into<U>`.
3+
14
use super::*;
25

36
pub trait From<T>: Sized {

src/debug.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! The native debug interface exposed to the ewasm contract. These functions are for testing
22
//! purposes only. On a live VM, any bytecode trying to import these symbols will be rejected.
33
4-
use crate::types::*;
4+
use crate::types::StorageKey;
55

6+
/// The native interface for debugging functions.
67
mod native {
78
extern "C" {
89
pub fn debug_print32(value: u32);
@@ -14,26 +15,32 @@ mod native {
1415
}
1516
}
1617

18+
/// Prints an unsigned 32-bit int.
1719
pub fn print32(value: u32) {
1820
unsafe { native::debug_print32(value) }
1921
}
2022

23+
/// Prints an unsigned 64-bit int.
2124
pub fn print64(value: u64) {
2225
unsafe { native::debug_print64(value) }
2326
}
2427

28+
/// Prints the contents of a slice.
2529
pub fn print_mem(slice: &[u8]) {
2630
unsafe { native::debug_printMem(slice.as_ptr() as *const u32, slice.len() as u32) }
2731
}
2832

33+
/// Prints the contents of a slice in hexadecimal format.
2934
pub fn print_mem_hex(slice: &[u8]) {
3035
unsafe { native::debug_printMemHex(slice.as_ptr() as *const u32, slice.len() as u32) }
3136
}
3237

38+
/// Prints the value of a storage key.
3339
pub fn print_storage(key: &StorageKey) {
3440
unsafe { native::debug_printStorage(key.bytes.as_ptr() as *const u32) }
3541
}
3642

43+
/// Prints the value of a storage key in hexadecimal format.
3744
pub fn print_storage_hex(key: &StorageKey) {
3845
unsafe { native::debug_printStorageHex(key.bytes.as_ptr() as *const u32) }
3946
}

src/lib.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
/// ewasm_api is a library used to interface with Ethereum's EEI in Ewasm, a set of enhancements to
2-
/// the Ethereum smart contract platform.
3-
/// ewasm_api exposes both a set of unsafe "native" functions representing the actual EEI
4-
/// functions, and a set of safe wrappers around them. It is recommended not to use the native
5-
/// functions as they do not perform bounds-checking.
6-
///
7-
/// To use ewasm_api, simply include it as a dependency in your project.
8-
///
9-
/// # Examples
10-
/// ```ignore
11-
/// extern crate ewasm_api;
12-
///
13-
/// use ewasm_api::{Hash, block_hash, finish_data};
14-
///
15-
/// #[cfg(target_arch = "wasm32")]
16-
/// #[no_mangle]
17-
/// pub extern "C" fn main() {
18-
/// let a: Hash = block_hash(1);
19-
/// finish_data(&a.bytes);
20-
/// }
21-
/// ```
1+
//! ewasm_api is a library used to interface with Ethereum's EEI in [Ewasm](https://github.com/ewasm/design), a set of enhancements to
2+
//! the Ethereum smart contract platform.
3+
//! ewasm_api exposes both a set of unsafe "native" functions representing the actual EEI
4+
//! functions, and a set of safe wrappers around them. It is recommended not to use the native
5+
//! functions as they do not perform bounds-checking.
6+
//!
7+
//! To use ewasm_api, simply include it as a dependency in your project.
8+
//! ewasm_api can be built with various feature sets:
9+
//! - `default`: Builds with `wee_alloc` as the global allocator and with the Rust standard
10+
//! library.
11+
//! - `qimalloc`: Builds with [qimalloc](https://github.com/wasmx/qimalloc) as the global
12+
//! allocator.
13+
//! - `debug`: Exposes the debugging interface.
14+
//! - `experimental`: Exposes the experimental bignum system library API.
15+
//!
16+
//! # Examples
17+
//! ```ignore
18+
//! extern crate ewasm_api;
19+
//!
20+
//! use ewasm_api::{Hash, block_hash, finish_data};
21+
//!
22+
//! #[cfg(target_arch = "wasm32")]
23+
//! #[no_mangle]
24+
//! pub extern "C" fn main() {
25+
//! let a: Hash = block_hash(1);
26+
//! finish_data(&a.bytes);
27+
//! }
28+
//! ```
2229
2330
#[macro_use]
2431
extern crate cfg_if;

src/native.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/// The native host interface exposed to the ewasm contract. Do not use these functions unless, for
2-
/// some reason, the safe wrapper is not flexible enough.
1+
//! The low-level bindings for the Ethereum Environment Interface (EEI). There is a safe set of wrappers for these functions, so use
2+
//! those unless you are certain you know what you're doing.
3+
34
extern "C" {
45
pub fn ethereum_useGas(amount: u64);
56
pub fn ethereum_getGasLeft() -> u64;

src/types.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! High-level types commonly used in Ethereum contracts.
2+
13
/// A little-endian unsigned 128-bit integer.
24
#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)]
35
pub struct Uint128 {
@@ -22,25 +24,25 @@ pub struct Bytes32 {
2224
pub bytes: [u8; 32],
2325
}
2426

25-
/// Type representing a value in wei.
27+
/// Type definition representing a value in wei.
2628
pub type EtherValue = Uint128;
2729

28-
/// Type representing an address.
30+
/// Type definition representing an address.
2931
pub type Address = Bytes20;
3032

31-
/// Type representing a storage key.
33+
/// Type definition representing a storage key.
3234
pub type StorageKey = Bytes32;
3335

34-
/// Type representing a storage value.
36+
/// Type definition representing a storage value.
3537
pub type StorageValue = Bytes32;
3638

37-
/// Type representing a log topic.
39+
/// Type definition representing a log topic.
3840
pub type LogTopic = Bytes32;
3941

40-
/// Type representing a Keccak-256 or SHA-256 hash.
42+
/// Type definition representing a Keccak-256 or SHA-256 hash.
4143
pub type Hash = Bytes32;
4244

43-
/// Type representing a block's difficulty.
45+
/// Type definition representing a block's difficulty.
4446
pub type Difficulty = Uint256;
4547

4648
macro_rules! from_primitive_impl {

src/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! General utility functions.
2+
3+
/// Allocate an owned buffer using the global allocator.
4+
/// Only enabled with `std`.
15
#[cfg(feature = "std")]
26
pub fn unsafe_alloc_buffer(len: usize) -> Vec<u8> {
37
let mut ret: Vec<u8> = Vec::with_capacity(len);

0 commit comments

Comments
 (0)