Documentation.

This commit is contained in:
Sergey Pepyakin 2019-01-25 11:33:03 +01:00
parent da384ed27a
commit cd9bcc073a
1 changed files with 11 additions and 0 deletions

View File

@ -1,9 +1,13 @@
//! This module contains auxilary functions which one might find useful for
//! generating implementations of host related functionality like `Externals`.
use nan_preserving_float::{F32, F64}; use nan_preserving_float::{F32, F64};
use {RuntimeValue, Trap, ValueType}; use {RuntimeValue, Trap, ValueType};
/// A trait that represents a value that can be directly coerced to one of /// A trait that represents a value that can be directly coerced to one of
/// wasm base value types. /// wasm base value types.
pub trait IntoWasmValue { pub trait IntoWasmValue {
/// The value type into which the self type is converted.
const VALUE_TYPE: ValueType; const VALUE_TYPE: ValueType;
/// Perform the conversion. /// Perform the conversion.
fn into_wasm_value(self) -> RuntimeValue; fn into_wasm_value(self) -> RuntimeValue;
@ -28,8 +32,15 @@ impl_convertible_to_wasm!(u64, I64, as i64);
impl_convertible_to_wasm!(F32, F32); impl_convertible_to_wasm!(F32, F32);
impl_convertible_to_wasm!(F64, F64); impl_convertible_to_wasm!(F64, F64);
/// A trait that represents a value that can be returned from a function.
///
/// Basically it is superset of `IntoWasmValue` types, adding the ability to return
/// the unit value (i.e. `()`) and return a value that signals a trap.
pub trait IntoWasmResult { pub trait IntoWasmResult {
/// The value type into which the self type is converted or `None` in case
/// of the unit value (aka `()` aka `void`).
const VALUE_TYPE: Option<ValueType>; const VALUE_TYPE: Option<ValueType>;
/// Perform the conversion.
fn into_wasm_result(self) -> Result<Option<RuntimeValue>, Trap>; fn into_wasm_result(self) -> Result<Option<RuntimeValue>, Trap>;
} }