From 70a2e612bcabbd0354d316d649d8480e3b89e9b9 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 19 Jun 2019 18:44:26 +0200 Subject: [PATCH] Satisfy cargo fmt style remarks --- src/memory.rs | 27 ++++++--------------------- src/module.rs | 7 +++++-- src/not_threadsafe.rs | 2 +- src/threadsafe.rs | 17 +++++++++-------- 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/memory.rs b/src/memory.rs index ea9aab0..8248197 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -1,10 +1,6 @@ #[allow(unused_imports)] use alloc::prelude::v1::*; -use core::{ - cmp, fmt, - ops::Range, - u32, -}; +use core::{cmp, fmt, ops::Range, u32}; use memory_units::{Bytes, Pages, RoundUpTo}; use parity_wasm::elements::ResizableLimits; use value::LittleEndianConvert; @@ -202,8 +198,7 @@ impl MemoryInstance { /// Get value from memory at given offset. pub fn get_value(&self, offset: u32) -> Result { - let region = - self.checked_region(offset as usize, ::core::mem::size_of::())?; + let region = self.checked_region(offset as usize, ::core::mem::size_of::())?; let buffer = self.buffer.borrow(); 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. pub fn set(&self, offset: u32, value: &[u8]) -> Result<(), Error> { - let range = self - .checked_region(offset as usize, value.len())? - .range(); + let range = self.checked_region(offset as usize, value.len())?.range(); if offset < self.lowest_used.get() { self.lowest_used.set(offset); @@ -298,11 +291,7 @@ impl MemoryInstance { Ok(size_before_grow) } - fn checked_region( - &self, - offset: usize, - size: usize, - ) -> Result { + fn checked_region(&self, offset: usize, size: usize) -> Result { let mut buffer = self.buffer.borrow_mut(); let end = offset.checked_add(size).ok_or_else(|| { Error::Memory(format!( @@ -472,12 +461,8 @@ impl MemoryInstance { return src.copy(src_offset, dst_offset, len); } - let src_range = src - .checked_region(src_offset, len)? - .range(); - let dst_range = dst - .checked_region(dst_offset, len)? - .range(); + let src_range = src.checked_region(src_offset, len)?.range(); + let dst_range = dst.checked_region(dst_offset, len)?.range(); if dst_offset < dst.lowest_used.get() as usize { dst.lowest_used.set(dst_offset as u32); diff --git a/src/module.rs b/src/module.rs index d167fe0..b559006 100644 --- a/src/module.rs +++ b/src/module.rs @@ -323,8 +323,11 @@ impl ModuleInstance { locals: body.locals().to_vec(), code: code, }; - let func_instance = - FuncInstance::alloc_internal(::MyRc::downgrade(&instance.0), signature, func_body); + let func_instance = FuncInstance::alloc_internal( + ::MyRc::downgrade(&instance.0), + signature, + func_body, + ); instance.push_func(func_instance); } } diff --git a/src/not_threadsafe.rs b/src/not_threadsafe.rs index d17d25a..eed3b27 100644 --- a/src/not_threadsafe.rs +++ b/src/not_threadsafe.rs @@ -1,5 +1,5 @@ pub use alloc::rc::Rc as MyRc; pub use alloc::rc::Weak as MyWeak; 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::RefCell as MyRefCell; diff --git a/src/threadsafe.rs b/src/threadsafe.rs index 0705c2f..046ce94 100644 --- a/src/threadsafe.rs +++ b/src/threadsafe.rs @@ -2,12 +2,8 @@ extern crate atomic; use alloc::sync::{Arc, Mutex}; -pub use alloc::sync::{ - Arc as MyRc, Weak as MyWeak, MutexGuard as MyRef, -}; -pub use self::atomic::{ - Atomic, Ordering::Relaxed as Ordering, -}; +pub use self::atomic::{Atomic, Ordering::Relaxed as Ordering}; +pub use alloc::sync::{Arc as MyRc, MutexGuard as MyRef, Weak as MyWeak}; /// Thread-safe wrapper which can be used in place of a `RefCell`. #[derive(Debug)] @@ -32,9 +28,14 @@ impl MyRefCell { /// Thread-safe wrapper which can be used in place of a `Cell`. #[derive(Debug)] -pub struct MyCell(Atomic) where T: Copy; +pub struct MyCell(Atomic) +where + T: Copy; -impl MyCell where T: Copy { +impl MyCell +where + T: Copy, +{ /// Create new wrapper object. pub fn new(obj: T) -> MyCell { MyCell(Atomic::new(obj))