mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-04-25 15:22:17 +00:00
2018 edition (#266)
* 2018 edition fixes * arrange uses * fix for nightly (but not tests) * fix for tests as well * fix spec runner
This commit is contained in:
parent
f9224f1ec1
commit
a959bb50a9
@ -11,6 +11,7 @@ description = "WebAssembly binary format serialization/deserialization/interpret
|
|||||||
keywords = ["wasm", "webassembly", "bytecode", "serde", "interpreter"]
|
keywords = ["wasm", "webassembly", "bytecode", "serde", "interpreter"]
|
||||||
categories = ["wasm", "parser-implementations"]
|
categories = ["wasm", "parser-implementations"]
|
||||||
exclude = [ "res/*", "spec/*" ]
|
exclude = [ "res/*", "spec/*" ]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
time = "0.1"
|
time = "0.1"
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use std::vec::Vec;
|
use crate::rust::vec::Vec;
|
||||||
use elements;
|
use crate::elements;
|
||||||
use super::invoke::{Invoke, Identity};
|
use super::{
|
||||||
use super::misc::{ValueTypeBuilder, ValueTypesBuilder, OptionalValueTypeBuilder};
|
invoke::{Invoke, Identity},
|
||||||
|
misc::{ValueTypeBuilder, ValueTypesBuilder, OptionalValueTypeBuilder},
|
||||||
|
};
|
||||||
|
|
||||||
/// Signature template description
|
/// Signature template description
|
||||||
pub enum Signature {
|
pub enum Signature {
|
||||||
@ -373,7 +375,7 @@ pub fn function() -> FunctionBuilder {
|
|||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::{signatures, function};
|
use super::{signatures, function};
|
||||||
use elements;
|
use crate::elements;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn example() {
|
fn example() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::vec::Vec;
|
use crate::rust::vec::Vec;
|
||||||
use super::invoke::{Identity, Invoke};
|
use super::invoke::{Identity, Invoke};
|
||||||
use elements;
|
use crate::elements;
|
||||||
|
|
||||||
/// Data segment builder
|
/// Data segment builder
|
||||||
pub struct DataSegmentBuilder<F=Identity> {
|
pub struct DataSegmentBuilder<F=Identity> {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use std::string::String;
|
use crate::rust::{string::String, borrow::ToOwned};
|
||||||
use std::borrow::ToOwned;
|
|
||||||
use super::invoke::{Invoke, Identity};
|
use super::invoke::{Invoke, Identity};
|
||||||
use elements;
|
use crate::elements;
|
||||||
|
|
||||||
/// Export entry builder
|
/// Export entry builder
|
||||||
pub struct ExportBuilder<F=Identity> {
|
pub struct ExportBuilder<F=Identity> {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
use super::invoke::{Invoke, Identity};
|
use super::{
|
||||||
use super::misc::ValueTypeBuilder;
|
invoke::{Invoke, Identity},
|
||||||
use elements;
|
misc::ValueTypeBuilder,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::elements;
|
||||||
|
|
||||||
/// Global builder
|
/// Global builder
|
||||||
pub struct GlobalBuilder<F=Identity> {
|
pub struct GlobalBuilder<F=Identity> {
|
||||||
@ -79,7 +82,7 @@ pub fn global() -> GlobalBuilder {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::global;
|
use super::global;
|
||||||
use elements;
|
use crate::elements;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn example() {
|
fn example() {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
|
use crate::rust::{borrow::ToOwned, string::String};
|
||||||
use super::invoke::{Identity, Invoke};
|
use super::invoke::{Identity, Invoke};
|
||||||
use elements;
|
use crate::elements;
|
||||||
use std::borrow::ToOwned;
|
|
||||||
use std::string::String;
|
|
||||||
|
|
||||||
/// Import builder
|
/// Import builder
|
||||||
pub struct ImportBuilder<F=Identity> {
|
pub struct ImportBuilder<F=Identity> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::vec::Vec;
|
use crate::rust::vec::Vec;
|
||||||
use elements;
|
use crate::elements;
|
||||||
use super::invoke::{Invoke, Identity};
|
use super::invoke::{Invoke, Identity};
|
||||||
|
|
||||||
/// Memory definition struct
|
/// Memory definition struct
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::vec::Vec;
|
use crate::rust::vec::Vec;
|
||||||
use super::invoke::{Invoke, Identity};
|
use super::invoke::{Invoke, Identity};
|
||||||
use elements;
|
use crate::elements;
|
||||||
|
|
||||||
pub struct ValueTypeBuilder<F=Identity> {
|
pub struct ValueTypeBuilder<F=Identity> {
|
||||||
callback: F,
|
callback: F,
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
use std::vec::Vec;
|
use crate::rust::vec::Vec;
|
||||||
use super::invoke::{Invoke, Identity};
|
use crate::elements;
|
||||||
use super::code::{self, SignaturesBuilder, FunctionBuilder};
|
use super::{
|
||||||
use super::memory::{self, MemoryBuilder};
|
import,
|
||||||
use super::table::{self, TableBuilder};
|
export,
|
||||||
use super::{import, export, global, data};
|
global,
|
||||||
use elements;
|
data,
|
||||||
|
invoke::{Invoke, Identity},
|
||||||
|
code::{self, SignaturesBuilder, FunctionBuilder},
|
||||||
|
memory::{self, MemoryBuilder},
|
||||||
|
table::{self, TableBuilder},
|
||||||
|
};
|
||||||
|
|
||||||
/// Module builder
|
/// Module builder
|
||||||
pub struct ModuleBuilder<F=Identity> {
|
pub struct ModuleBuilder<F=Identity> {
|
||||||
@ -522,6 +527,7 @@ pub fn from_module(module: elements::Module) -> ModuleBuilder {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
|
use crate::elements;
|
||||||
use super::module;
|
use super::module;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -556,7 +562,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn global() {
|
fn global() {
|
||||||
let module = module()
|
let module = module()
|
||||||
.global().value_type().i64().mutable().init_expr(::elements::Instruction::I64Const(5)).build()
|
.global().value_type().i64().mutable().init_expr(elements::Instruction::I64Const(5)).build()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1);
|
assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1);
|
||||||
@ -566,7 +572,7 @@ mod tests {
|
|||||||
fn data() {
|
fn data() {
|
||||||
let module = module()
|
let module = module()
|
||||||
.data()
|
.data()
|
||||||
.offset(::elements::Instruction::I32Const(16))
|
.offset(elements::Instruction::I32Const(16))
|
||||||
.value(vec![0u8, 15, 10, 5, 25])
|
.value(vec![0u8, 15, 10, 5, 25])
|
||||||
.build()
|
.build()
|
||||||
.build();
|
.build();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::vec::Vec;
|
use crate::rust::vec::Vec;
|
||||||
use elements;
|
use crate::elements;
|
||||||
use super::invoke::{Invoke, Identity};
|
use super::invoke::{Invoke, Identity};
|
||||||
|
|
||||||
/// Table definition
|
/// Table definition
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::string::String;
|
use crate::rust::string::String;
|
||||||
use super::{Deserialize, Serialize, Error, VarUint7, VarUint32};
|
use super::{Deserialize, Serialize, Error, VarUint7, VarUint32};
|
||||||
use io;
|
use crate::io;
|
||||||
|
|
||||||
/// Internal reference of the exported entry.
|
/// Internal reference of the exported entry.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use io;
|
use crate::rust::vec::Vec;
|
||||||
use std::vec::Vec;
|
|
||||||
use super::{
|
use super::{
|
||||||
Deserialize, Error, ValueType, VarUint32, CountedList, Instructions,
|
Deserialize, Error, ValueType, VarUint32, CountedList, Instructions,
|
||||||
Serialize, CountedWriter, CountedListWriter,
|
Serialize, CountedWriter, CountedListWriter,
|
||||||
};
|
};
|
||||||
use elements::section::SectionReader;
|
use crate::{io, elements::section::SectionReader};
|
||||||
|
|
||||||
/// Function signature (type reference)
|
/// Function signature (type reference)
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use io;
|
use crate::io;
|
||||||
use super::{Deserialize, Serialize, Error, GlobalType, InitExpr};
|
use super::{Deserialize, Serialize, Error, GlobalType, InitExpr};
|
||||||
|
|
||||||
/// Global entry in the module.
|
/// Global entry in the module.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use io;
|
use crate::rust::string::String;
|
||||||
use std::string::String;
|
use crate::io;
|
||||||
use super::{
|
use super::{
|
||||||
Deserialize, Serialize, Error, VarUint7, VarInt7, VarUint32, VarUint1, Uint8,
|
Deserialize, Serialize, Error, VarUint7, VarInt7, VarUint32, VarUint1, Uint8,
|
||||||
ValueType, TableElementType
|
ValueType, TableElementType
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
use std::cmp::min;
|
use crate::rust::{
|
||||||
use std::iter::{FromIterator, IntoIterator};
|
cmp::min,
|
||||||
use std::mem;
|
iter::{FromIterator, IntoIterator},
|
||||||
use std::slice;
|
mem,
|
||||||
use std::vec;
|
slice,
|
||||||
use std::vec::Vec;
|
vec::{self, Vec},
|
||||||
use io;
|
};
|
||||||
|
|
||||||
|
use crate::io;
|
||||||
|
|
||||||
use super::{Deserialize, Error, Serialize, VarUint32};
|
use super::{Deserialize, Error, Serialize, VarUint32};
|
||||||
|
|
||||||
@ -86,7 +88,7 @@ impl<T> IndexMap<T> {
|
|||||||
existing
|
existing
|
||||||
};
|
};
|
||||||
if mem::size_of::<usize>() > 4 {
|
if mem::size_of::<usize>() > 4 {
|
||||||
debug_assert!(self.entries.len() <= (::std::u32::MAX as usize) + 1);
|
debug_assert!(self.entries.len() <= (u32::max_value() as usize) + 1);
|
||||||
}
|
}
|
||||||
#[cfg(slow_assertions)]
|
#[cfg(slow_assertions)]
|
||||||
debug_assert_eq!(self.len, self.slow_len());
|
debug_assert_eq!(self.len, self.slow_len());
|
||||||
@ -357,7 +359,7 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use io;
|
use crate::io;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
//! Elements of the WebAssembly binary format.
|
//! Elements of the WebAssembly binary format.
|
||||||
|
|
||||||
use std::fmt;
|
use crate::rust::{fmt, vec::Vec, format, string::String};
|
||||||
use io;
|
use crate::io;
|
||||||
use std::vec::Vec;
|
|
||||||
use std::string::String;
|
|
||||||
|
|
||||||
macro_rules! buffered_read {
|
macro_rules! buffered_read {
|
||||||
($buffer_size: expr, $length: expr, $reader: expr) => {
|
($buffer_size: expr, $length: expr, $reader: expr) => {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use io;
|
use crate::rust::{vec::Vec, borrow::ToOwned, string::String, cmp};
|
||||||
use std::vec::Vec;
|
use crate::io;
|
||||||
use std::borrow::ToOwned;
|
|
||||||
use std::string::String;
|
|
||||||
|
|
||||||
use super::{Deserialize, Serialize, Error, Uint32, External};
|
use super::{Deserialize, Serialize, Error, Uint32, External};
|
||||||
use super::section::{
|
use super::section::{
|
||||||
@ -539,7 +537,7 @@ struct PeekSection<'a> {
|
|||||||
|
|
||||||
impl<'a> io::Read for PeekSection<'a> {
|
impl<'a> io::Read for PeekSection<'a> {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<()> {
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<()> {
|
||||||
let available = ::std::cmp::min(buf.len(), self.region.len() - self.cursor);
|
let available = cmp::min(buf.len(), self.region.len() - self.cursor);
|
||||||
if available < buf.len() {
|
if available < buf.len() {
|
||||||
return Err(io::Error::UnexpectedEof);
|
return Err(io::Error::UnexpectedEof);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use io;
|
use crate::rust::{vec::Vec, string::String};
|
||||||
use std::vec::Vec;
|
use crate::io;
|
||||||
use std::string::String;
|
|
||||||
|
|
||||||
use super::{Deserialize, Error, Module, Serialize, VarUint32, VarUint7, Type};
|
use super::{Deserialize, Error, Module, Serialize, VarUint32, VarUint7, Type};
|
||||||
use super::index_map::IndexMap;
|
use super::index_map::IndexMap;
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use std::fmt;
|
use crate::rust::{fmt, vec::Vec, boxed::Box};
|
||||||
use std::vec::Vec;
|
use crate::io;
|
||||||
use std::boxed::Box;
|
|
||||||
use io;
|
|
||||||
use super::{
|
use super::{
|
||||||
Serialize, Deserialize, Error,
|
Serialize, Deserialize, Error,
|
||||||
Uint8, VarUint32, CountedList, BlockType,
|
Uint8, VarUint32, CountedList, BlockType,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use io;
|
use crate::rust::{vec::Vec, string::String};
|
||||||
use std::vec::Vec;
|
use crate::{io, elements};
|
||||||
use std::string::String;
|
|
||||||
use super::{Error, Deserialize, Serialize};
|
use super::{Error, Deserialize, Serialize};
|
||||||
|
|
||||||
/// Unsigned variable-length integer, limited to 32 bits,
|
/// Unsigned variable-length integer, limited to 32 bits,
|
||||||
@ -28,7 +27,7 @@ impl From<u32> for VarUint32 {
|
|||||||
|
|
||||||
impl From<usize> for VarUint32 {
|
impl From<usize> for VarUint32 {
|
||||||
fn from(i: usize) -> VarUint32 {
|
fn from(i: usize) -> VarUint32 {
|
||||||
assert!(i <= ::std::u32::MAX as usize);
|
assert!(i <= u32::max_value() as usize);
|
||||||
VarUint32(i as u32)
|
VarUint32(i as u32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -600,9 +599,9 @@ impl<'a, W: 'a + io::Write> io::Write for CountedWriter<'a, W> {
|
|||||||
/// Helper struct to write series of `T` preceded by the length of the sequence
|
/// Helper struct to write series of `T` preceded by the length of the sequence
|
||||||
/// serialized as VarUint32.
|
/// serialized as VarUint32.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CountedListWriter<I: Serialize<Error=::elements::Error>, T: IntoIterator<Item=I>>(pub usize, pub T);
|
pub struct CountedListWriter<I: Serialize<Error=elements::Error>, T: IntoIterator<Item=I>>(pub usize, pub T);
|
||||||
|
|
||||||
impl<I: Serialize<Error=::elements::Error>, T: IntoIterator<Item=I>> Serialize for CountedListWriter<I, T> {
|
impl<I: Serialize<Error=elements::Error>, T: IntoIterator<Item=I>> Serialize for CountedListWriter<I, T> {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn serialize<W: io::Write>(self, writer: &mut W) -> Result<(), Self::Error> {
|
fn serialize<W: io::Write>(self, writer: &mut W) -> Result<(), Self::Error> {
|
||||||
@ -622,7 +621,7 @@ mod tests {
|
|||||||
|
|
||||||
use super::super::{deserialize_buffer, Serialize};
|
use super::super::{deserialize_buffer, Serialize};
|
||||||
use super::{CountedList, VarInt7, VarUint32, VarInt32, VarInt64, VarUint64};
|
use super::{CountedList, VarInt7, VarUint32, VarInt32, VarInt64, VarUint64};
|
||||||
use elements::Error;
|
use crate::elements::Error;
|
||||||
|
|
||||||
fn varuint32_ser_test(val: u32, expected: Vec<u8>) {
|
fn varuint32_ser_test(val: u32, expected: Vec<u8>) {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use io;
|
use crate::rust::{vec::Vec, string::String};
|
||||||
use std::vec::Vec;
|
use crate::io;
|
||||||
use std::string::String;
|
|
||||||
|
|
||||||
use super::{CountedList, CountedListWriter, CountedWriter, Deserialize, Error, Serialize, VarInt32, VarUint32, VarUint7};
|
use super::{CountedList, CountedListWriter, CountedWriter, Deserialize, Error, Serialize, VarInt32, VarUint32, VarUint7};
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use io;
|
use crate::rust::{vec::Vec, string::String, borrow::ToOwned};
|
||||||
use std::vec::Vec;
|
use crate::{io, elements};
|
||||||
use std::string::String;
|
|
||||||
use std::borrow::ToOwned;
|
|
||||||
use super::{
|
use super::{
|
||||||
Serialize,
|
Serialize,
|
||||||
Deserialize,
|
Deserialize,
|
||||||
@ -254,7 +252,7 @@ pub(crate) struct SectionReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SectionReader {
|
impl SectionReader {
|
||||||
pub fn new<R: io::Read>(reader: &mut R) -> Result<Self, ::elements::Error> {
|
pub fn new<R: io::Read>(reader: &mut R) -> Result<Self, elements::Error> {
|
||||||
let length = u32::from(VarUint32::deserialize(reader)?) as usize;
|
let length = u32::from(VarUint32::deserialize(reader)?) as usize;
|
||||||
let inner_buffer = buffered_read!(ENTRIES_BUFFER_LENGTH, length, reader);
|
let inner_buffer = buffered_read!(ENTRIES_BUFFER_LENGTH, length, reader);
|
||||||
let buf_length = inner_buffer.len();
|
let buf_length = inner_buffer.len();
|
||||||
@ -285,8 +283,8 @@ impl io::Read for SectionReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_entries<R: io::Read, T: Deserialize<Error=::elements::Error>>(reader: &mut R)
|
fn read_entries<R: io::Read, T: Deserialize<Error=elements::Error>>(reader: &mut R)
|
||||||
-> Result<Vec<T>, ::elements::Error>
|
-> Result<Vec<T>, elements::Error>
|
||||||
{
|
{
|
||||||
let mut section_reader = SectionReader::new(reader)?;
|
let mut section_reader = SectionReader::new(reader)?;
|
||||||
let result = CountedList::<T>::deserialize(&mut section_reader)?.into_inner();
|
let result = CountedList::<T>::deserialize(&mut section_reader)?.into_inner();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use io;
|
use crate::rust::vec::Vec;
|
||||||
use std::vec::Vec;
|
use crate::io;
|
||||||
use super::{Deserialize, Serialize, Error, VarUint32, CountedList, InitExpr, CountedListWriter};
|
use super::{Deserialize, Serialize, Error, VarUint32, CountedList, InitExpr, CountedListWriter};
|
||||||
|
|
||||||
const FLAG_MEMZERO: u32 = 0;
|
const FLAG_MEMZERO: u32 = 0;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use io;
|
use crate::rust::{fmt, vec::Vec};
|
||||||
use std::fmt;
|
use crate::io;
|
||||||
use std::vec::Vec;
|
|
||||||
use super::{
|
use super::{
|
||||||
Deserialize, Serialize, Error, VarUint7, VarInt7, VarUint1, CountedList,
|
Deserialize, Serialize, Error, VarUint7, VarInt7, VarUint1, CountedList,
|
||||||
CountedListWriter, VarUint32,
|
CountedListWriter, VarUint32,
|
||||||
|
18
src/io.rs
18
src/io.rs
@ -3,6 +3,14 @@
|
|||||||
//! Basically it just a replacement for the std::io that is usable from
|
//! Basically it just a replacement for the std::io that is usable from
|
||||||
//! the `no_std` environment.
|
//! the `no_std` environment.
|
||||||
|
|
||||||
|
use crate::rust::result;
|
||||||
|
|
||||||
|
#[cfg(feature="std")]
|
||||||
|
use crate::rust::io;
|
||||||
|
|
||||||
|
#[cfg(not(feature="std"))]
|
||||||
|
use crate::rust::vec::Vec;
|
||||||
|
|
||||||
/// IO specific error.
|
/// IO specific error.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
@ -16,11 +24,11 @@ pub enum Error {
|
|||||||
InvalidData,
|
InvalidData,
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
IoError(::std::io::Error),
|
IoError(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// IO specific Result.
|
/// IO specific Result.
|
||||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
pub trait Write {
|
pub trait Write {
|
||||||
/// Write a buffer of data into this write.
|
/// Write a buffer of data into this write.
|
||||||
@ -70,7 +78,7 @@ impl<T: AsRef<[u8]>> Read for Cursor<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
impl Write for ::std::vec::Vec<u8> {
|
impl Write for Vec<u8> {
|
||||||
fn write(&mut self, buf: &[u8]) -> Result<()> {
|
fn write(&mut self, buf: &[u8]) -> Result<()> {
|
||||||
self.extend(buf);
|
self.extend(buf);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -78,7 +86,7 @@ impl Write for ::std::vec::Vec<u8> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl<T: ::std::io::Read> Read for T {
|
impl<T: io::Read> Read for T {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<()> {
|
fn read(&mut self, buf: &mut [u8]) -> Result<()> {
|
||||||
self.read_exact(buf)
|
self.read_exact(buf)
|
||||||
.map_err(Error::IoError)
|
.map_err(Error::IoError)
|
||||||
@ -86,7 +94,7 @@ impl<T: ::std::io::Read> Read for T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl<T: ::std::io::Write> Write for T {
|
impl<T: io::Write> Write for T {
|
||||||
fn write(&mut self, buf: &[u8]) -> Result<()> {
|
fn write(&mut self, buf: &[u8]) -> Result<()> {
|
||||||
self.write_all(buf).map_err(Error::IoError)
|
self.write_all(buf).map_err(Error::IoError)
|
||||||
}
|
}
|
||||||
|
24
src/lib.rs
24
src/lib.rs
@ -1,12 +1,10 @@
|
|||||||
//! WebAssembly format library
|
//! WebAssembly format library
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
||||||
|
|
||||||
#![warn(missing_docs)]
|
#[cfg(not(feature="std"))] #[macro_use]
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
pub mod elements;
|
pub mod elements;
|
||||||
@ -26,13 +24,17 @@ pub use elements::{
|
|||||||
serialize_to_file,
|
serialize_to_file,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
mod std {
|
pub (crate) mod rust {
|
||||||
pub use core::*;
|
pub use core::*;
|
||||||
pub use alloc::vec;
|
pub use ::alloc::format;
|
||||||
pub use alloc::string;
|
pub use ::alloc::vec;
|
||||||
pub use alloc::boxed;
|
pub use ::alloc::string;
|
||||||
pub use alloc::borrow;
|
pub use ::alloc::boxed;
|
||||||
|
pub use ::alloc::borrow;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature="std")]
|
||||||
|
pub (crate) mod rust {
|
||||||
|
pub use std::*;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user