Merge pull request #142 from paritytech/doc-update

Fix missing docs warnings
This commit is contained in:
Nikolay Volf 2018-01-10 12:07:21 +04:00 committed by GitHub
commit 657ee416c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 2 deletions

View File

@ -255,8 +255,11 @@ impl<F> FuncBodyBuilder<F> where F: Invoke<elements::FuncBody> {
/// Function definition (extended structure to specify function entirely, incl. signature, mainness and code)
pub struct FunctionDefinition {
/// Is this function is start function
pub is_main: bool,
/// Signature description
pub signature: Signature,
/// Body (code) of the function
pub code: elements::FuncBody,
}

View File

@ -9,6 +9,7 @@ pub struct ExportBuilder<F=Identity> {
}
impl ExportBuilder {
/// New export builder
pub fn new() -> Self {
ExportBuilder::with_callback(Identity)
}

View File

@ -2,6 +2,7 @@ use super::invoke::{Invoke, Identity};
use super::misc::ValueTypeBuilder;
use elements;
/// Global builder
pub struct GlobalBuilder<F=Identity> {
callback: F,
value_type: elements::ValueType,
@ -10,12 +11,14 @@ pub struct GlobalBuilder<F=Identity> {
}
impl GlobalBuilder {
/// New global builder
pub fn new() -> Self {
GlobalBuilder::with_callback(Identity)
}
}
impl<F> GlobalBuilder<F> {
/// New global builder with callback (in chained context)
pub fn with_callback(callback: F) -> Self {
GlobalBuilder {
callback: callback,
@ -25,31 +28,36 @@ impl<F> GlobalBuilder<F> {
}
}
/// Set/override resulting global type
pub fn with_type(mut self, value_type: elements::ValueType) -> Self {
self.value_type = value_type;
self
}
/// Set mutabilty to true
pub fn mutable(mut self) -> Self {
self.is_mutable = true;
self
}
/// Set initialization expression opcode for this global (`end` opcode will be added automatically)
pub fn init_expr(mut self, opcode: elements::Opcode) -> Self {
self.init_expr = elements::InitExpr::new(vec![opcode, elements::Opcode::End]);
self
}
/// Start value type builder
pub fn value_type(self) -> ValueTypeBuilder<Self> {
ValueTypeBuilder::with_callback(self)
}
}
impl<F> GlobalBuilder<F> where F: Invoke<elements::GlobalEntry> {
/// Finalize current builder spawning resulting struct
pub fn build(self) -> F::Result {
self.callback.invoke(
elements::GlobalEntry::new(
elements::GlobalType::new(self.value_type, self.is_mutable),
elements::GlobalType::new(self.value_type, self.is_mutable),
self.init_expr,
)
)

View File

@ -1,6 +1,7 @@
use super::invoke::{Invoke, Identity};
use elements;
/// Import builder
pub struct ImportBuilder<F=Identity> {
callback: F,
module: String,
@ -9,13 +10,14 @@ pub struct ImportBuilder<F=Identity> {
}
impl ImportBuilder {
/// New import builder
pub fn new() -> Self {
ImportBuilder::with_callback(Identity)
}
}
impl<F> ImportBuilder<F> {
/// New import builder with callback (in chained context)
pub fn with_callback(callback: F) -> Self {
ImportBuilder {
callback: callback,
@ -25,31 +27,37 @@ impl<F> ImportBuilder<F> {
}
}
/// Set/override module name
pub fn module(mut self, name: &str) -> Self {
self.module = name.to_owned();
self
}
/// Set/override field name
pub fn field(mut self, name: &str) -> Self {
self.field = name.to_owned();
self
}
/// Set/override both module name and field name
pub fn path(self, module: &str, field: &str) -> Self {
self.module(module).field(field)
}
/// Set/override external mapping for this import
pub fn with_external(mut self, external: elements::External) -> Self {
self.binding = external;
self
}
/// Start new external mapping builder
pub fn external(self) -> ImportExternalBuilder<Self> {
ImportExternalBuilder::with_callback(self)
}
}
impl<F> ImportBuilder<F> where F: Invoke<elements::ImportEntry> {
/// Finalize current builder spawning the resulting struct
pub fn build(self) -> F::Result {
self.callback.invoke(elements::ImportEntry::new(self.module, self.field, self.binding))
}
@ -62,12 +70,14 @@ impl<F> Invoke<elements::External> for ImportBuilder<F> {
}
}
/// Import to external mapping builder
pub struct ImportExternalBuilder<F=Identity> {
callback: F,
binding: elements::External,
}
impl<F> ImportExternalBuilder<F> where F: Invoke<elements::External> {
/// New import to external mapping builder with callback (in chained context)
pub fn with_callback(callback: F) -> Self {
ImportExternalBuilder{
callback: callback,
@ -75,21 +85,25 @@ impl<F> ImportExternalBuilder<F> where F: Invoke<elements::External> {
}
}
/// Function mapping with type reference
pub fn func(mut self, index: u32) -> F::Result {
self.binding = elements::External::Function(index);
self.callback.invoke(self.binding)
}
/// Memory mapping with specified limits
pub fn memory(mut self, min: u32, max: Option<u32>) -> F::Result {
self.binding = elements::External::Memory(elements::MemoryType::new(min, max));
self.callback.invoke(self.binding)
}
/// Table mapping with specified limits
pub fn table(mut self, min: u32, max: Option<u32>) -> F::Result {
self.binding = elements::External::Table(elements::TableType::new(min, max));
self.callback.invoke(self.binding)
}
/// Global mapping with speciifed type and mutability
pub fn global(mut self, value_type: elements::ValueType, is_mut: bool) -> F::Result {
self.binding = elements::External::Global(elements::GlobalType::new(value_type, is_mut));
self.callback.invoke(self.binding)

View File

@ -1,31 +1,41 @@
use elements;
use super::invoke::{Invoke, Identity};
/// Memory definition struct
#[derive(Debug)]
pub struct MemoryDefinition {
/// Minimum memory size
pub min: u32,
/// Maximum memory size
pub max: Option<u32>,
/// Memory data segments (static regions)
pub data: Vec<MemoryDataDefinition>,
}
/// Memory static region entry definition
#[derive(Debug)]
pub struct MemoryDataDefinition {
/// Segment initialization expression for offset
pub offset: elements::InitExpr,
/// Raw bytes of static region
pub values: Vec<u8>,
}
/// Memory and static regions builder
pub struct MemoryBuilder<F=Identity> {
callback: F,
memory: MemoryDefinition,
}
impl MemoryBuilder {
/// New memory builder
pub fn new() -> Self {
MemoryBuilder::with_callback(Identity)
}
}
impl<F> MemoryBuilder<F> where F: Invoke<MemoryDefinition> {
/// New memory builder with callback (in chained context)
pub fn with_callback(callback: F) -> Self {
MemoryBuilder {
callback: callback,
@ -33,16 +43,19 @@ impl<F> MemoryBuilder<F> where F: Invoke<MemoryDefinition> {
}
}
/// Set/override minimum size
pub fn with_min(mut self, min: u32) -> Self {
self.memory.min = min;
self
}
/// Set/override maximum size
pub fn with_max(mut self, max: Option<u32>) -> Self {
self.memory.max = max;
self
}
/// Push new static region with initialized offset expression and raw bytes
pub fn with_data(mut self, index: u32, values: Vec<u8>) -> Self {
self.memory.data.push(MemoryDataDefinition {
offset: elements::InitExpr::new(vec![
@ -54,6 +67,7 @@ impl<F> MemoryBuilder<F> where F: Invoke<MemoryDefinition> {
self
}
/// Finalize current builder, spawning resulting struct
pub fn build(self) -> F::Result {
self.callback.invoke(self.memory)
}

View File

@ -1,31 +1,41 @@
use elements;
use super::invoke::{Invoke, Identity};
/// Table definition
#[derive(Debug)]
pub struct TableDefinition {
/// Minimum length
pub min: u32,
/// Maximum length, if any
pub max: Option<u32>,
/// Element segments, if any
pub elements: Vec<TableEntryDefinition>,
}
/// Table elements entry definition
#[derive(Debug)]
pub struct TableEntryDefinition {
/// Offset initialization expression
pub offset: elements::InitExpr,
/// Values of initialization
pub values: Vec<u32>,
}
/// Table builder
pub struct TableBuilder<F=Identity> {
callback: F,
table: TableDefinition,
}
impl TableBuilder {
/// New table builder
pub fn new() -> Self {
TableBuilder::with_callback(Identity)
}
}
impl<F> TableBuilder<F> where F: Invoke<TableDefinition> {
/// New table builder with callback in chained context
pub fn with_callback(callback: F) -> Self {
TableBuilder {
callback: callback,
@ -33,16 +43,19 @@ impl<F> TableBuilder<F> where F: Invoke<TableDefinition> {
}
}
/// Set/override minimum length
pub fn with_min(mut self, min: u32) -> Self {
self.table.min = min;
self
}
/// Set/override maximum length
pub fn with_max(mut self, max: Option<u32>) -> Self {
self.table.max = max;
self
}
/// Generate initialization expression and element values on specified index
pub fn with_element(mut self, index: u32, values: Vec<u32>) -> Self {
self.table.elements.push(TableEntryDefinition {
offset: elements::InitExpr::new(vec![
@ -54,6 +67,7 @@ impl<F> TableBuilder<F> where F: Invoke<TableDefinition> {
self
}
/// Finalize current builder spawning resulting struct
pub fn build(self) -> F::Result {
self.callback.invoke(self.table)
}