Satisfy cargo fmt style remarks

This commit is contained in:
Michael Mueller 2019-06-19 18:44:26 +02:00
parent 81f34a6ab6
commit 70a2e612bc
No known key found for this signature in database
GPG Key ID: 95756F716F423159
4 changed files with 21 additions and 32 deletions

View File

@ -1,10 +1,6 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::v1::*; use alloc::prelude::v1::*;
use core::{ use core::{cmp, fmt, ops::Range, u32};
cmp, fmt,
ops::Range,
u32,
};
use memory_units::{Bytes, Pages, RoundUpTo}; use memory_units::{Bytes, Pages, RoundUpTo};
use parity_wasm::elements::ResizableLimits; use parity_wasm::elements::ResizableLimits;
use value::LittleEndianConvert; use value::LittleEndianConvert;
@ -202,8 +198,7 @@ impl MemoryInstance {
/// Get value from memory at given offset. /// Get value from memory at given offset.
pub fn get_value<T: LittleEndianConvert>(&self, offset: u32) -> Result<T, Error> { pub fn get_value<T: LittleEndianConvert>(&self, offset: u32) -> Result<T, Error> {
let region = let region = self.checked_region(offset as usize, ::core::mem::size_of::<T>())?;
self.checked_region(offset as usize, ::core::mem::size_of::<T>())?;
let buffer = self.buffer.borrow(); let buffer = self.buffer.borrow();
Ok(T::from_little_endian(&buffer[region.range()]).expect("Slice size is checked")) Ok(T::from_little_endian(&buffer[region.range()]).expect("Slice size is checked"))
@ -238,9 +233,7 @@ impl MemoryInstance {
/// Copy data in the memory at given offset. /// Copy data in the memory at given offset.
pub fn set(&self, offset: u32, value: &[u8]) -> Result<(), Error> { pub fn set(&self, offset: u32, value: &[u8]) -> Result<(), Error> {
let range = self let range = self.checked_region(offset as usize, value.len())?.range();
.checked_region(offset as usize, value.len())?
.range();
if offset < self.lowest_used.get() { if offset < self.lowest_used.get() {
self.lowest_used.set(offset); self.lowest_used.set(offset);
@ -298,11 +291,7 @@ impl MemoryInstance {
Ok(size_before_grow) Ok(size_before_grow)
} }
fn checked_region( fn checked_region(&self, offset: usize, size: usize) -> Result<CheckedRegion, Error> {
&self,
offset: usize,
size: usize,
) -> Result<CheckedRegion, Error> {
let mut buffer = self.buffer.borrow_mut(); let mut buffer = self.buffer.borrow_mut();
let end = offset.checked_add(size).ok_or_else(|| { let end = offset.checked_add(size).ok_or_else(|| {
Error::Memory(format!( Error::Memory(format!(
@ -472,12 +461,8 @@ impl MemoryInstance {
return src.copy(src_offset, dst_offset, len); return src.copy(src_offset, dst_offset, len);
} }
let src_range = src let src_range = src.checked_region(src_offset, len)?.range();
.checked_region(src_offset, len)? let dst_range = dst.checked_region(dst_offset, len)?.range();
.range();
let dst_range = dst
.checked_region(dst_offset, len)?
.range();
if dst_offset < dst.lowest_used.get() as usize { if dst_offset < dst.lowest_used.get() as usize {
dst.lowest_used.set(dst_offset as u32); dst.lowest_used.set(dst_offset as u32);

View File

@ -323,8 +323,11 @@ impl ModuleInstance {
locals: body.locals().to_vec(), locals: body.locals().to_vec(),
code: code, code: code,
}; };
let func_instance = let func_instance = FuncInstance::alloc_internal(
FuncInstance::alloc_internal(::MyRc::downgrade(&instance.0), signature, func_body); ::MyRc::downgrade(&instance.0),
signature,
func_body,
);
instance.push_func(func_instance); instance.push_func(func_instance);
} }
} }

View File

@ -1,5 +1,5 @@
pub use alloc::rc::Rc as MyRc; pub use alloc::rc::Rc as MyRc;
pub use alloc::rc::Weak as MyWeak; pub use alloc::rc::Weak as MyWeak;
pub use core::cell::Cell as MyCell; pub use core::cell::Cell as MyCell;
pub use core::cell::RefCell as MyRefCell;
pub use core::cell::Ref as MyRef; pub use core::cell::Ref as MyRef;
pub use core::cell::RefCell as MyRefCell;

View File

@ -2,12 +2,8 @@ extern crate atomic;
use alloc::sync::{Arc, Mutex}; use alloc::sync::{Arc, Mutex};
pub use alloc::sync::{ pub use self::atomic::{Atomic, Ordering::Relaxed as Ordering};
Arc as MyRc, Weak as MyWeak, MutexGuard as MyRef, pub use alloc::sync::{Arc as MyRc, MutexGuard as MyRef, Weak as MyWeak};
};
pub use self::atomic::{
Atomic, Ordering::Relaxed as Ordering,
};
/// Thread-safe wrapper which can be used in place of a `RefCell`. /// Thread-safe wrapper which can be used in place of a `RefCell`.
#[derive(Debug)] #[derive(Debug)]
@ -32,9 +28,14 @@ impl<T> MyRefCell<T> {
/// Thread-safe wrapper which can be used in place of a `Cell`. /// Thread-safe wrapper which can be used in place of a `Cell`.
#[derive(Debug)] #[derive(Debug)]
pub struct MyCell<T>(Atomic<T>) where T: Copy; pub struct MyCell<T>(Atomic<T>)
where
T: Copy;
impl<T> MyCell<T> where T: Copy { impl<T> MyCell<T>
where
T: Copy,
{
/// Create new wrapper object. /// Create new wrapper object.
pub fn new(obj: T) -> MyCell<T> { pub fn new(obj: T) -> MyCell<T> {
MyCell(Atomic::new(obj)) MyCell(Atomic::new(obj))