add rustfmt config

This commit is contained in:
vms 2020-06-03 23:08:18 +03:00
parent 66ca7345fd
commit 44c098ec5b
9 changed files with 40 additions and 27 deletions

4
.rustfmt.toml Normal file
View File

@ -0,0 +1,4 @@
edition = "2018"
reorder_imports = false
reorder_modules = false

View File

@ -56,7 +56,7 @@ impl Default for FCEModuleConfig {
wasi_version: WasiVersion::Latest,
wasi_envs: vec![],
wasi_preopened_files: vec![],
wasi_mapped_dirs: vec![]
wasi_mapped_dirs: vec![],
}
}
}

View File

@ -72,16 +72,23 @@ impl std::fmt::Display for FCEError {
FCEError::PrepareError(msg) => {
write!(f, "Prepare error: {}, probably module is mailformed", msg)
}
FCEError::NonUniqueModuleName => {
write!(f, "FCE already has module with such a name")
}
FCEError::NonUniqueModuleName => write!(f, "FCE already has module with such a name"),
FCEError::NoSuchFunction(msg) => {
write!(f, "FCE doesn't have a function with such a name: {}", msg)
}
FCEError::NoSuchModule => write!(f, "FCE doesn't have a module with such a name"),
FCEError::NoWITSection => write!(f, "Loaded module doesn't contain WIT section that is neccessary for instantiation"),
FCEError::MultipleWITSections => write!(f, "Loaded module contains multiple WIT sections that is unsupported now"),
FCEError::WITRemainderNotEmpty => write!(f, "WIT section remainder isn't empty - WIT section possibly corrupted"),
FCEError::NoWITSection => write!(
f,
"Loaded module doesn't contain WIT section that is neccessary for instantiation"
),
FCEError::MultipleWITSections => write!(
f,
"Loaded module contains multiple WIT sections that is unsupported now"
),
FCEError::WITRemainderNotEmpty => write!(
f,
"WIT section remainder isn't empty - WIT section possibly corrupted"
),
FCEError::WITParseError => write!(f, "WIT section is corrupted"),
}
}

View File

@ -41,7 +41,12 @@ impl Default for FCE {
}
impl FCEService for FCE {
fn call(&mut self, module_name: &str, func_name: &str, argument: &[IValue]) -> Result<Vec<IValue>, FCEError> {
fn call(
&mut self,
module_name: &str,
func_name: &str,
argument: &[IValue],
) -> Result<Vec<IValue>, FCEError> {
match self.modules.get_mut(module_name) {
// TODO: refactor errors
Some(mut module) => unsafe {
@ -57,23 +62,19 @@ impl FCEService for FCE {
wasm_bytes: &[u8],
config: FCEModuleConfig,
) -> Result<(), FCEError>
where
S: Into<String>,
where
S: Into<String>,
{
let _prepared_wasm_bytes =
super::prepare::prepare_module(wasm_bytes, config.mem_pages_count)?;
let module = FCEModule::new(
&wasm_bytes,
config.import_object,
&self.modules,
)?;
let module = FCEModule::new(&wasm_bytes, config.import_object, &self.modules)?;
match self.modules.entry(module_name.into()) {
Entry::Vacant(entry) => {
entry.insert(Arc::new(module));
Ok(())
},
}
Entry::Occupied(_) => Err(FCEError::NonUniqueModuleName),
}
}

View File

@ -21,7 +21,12 @@ use super::IValue;
/// Describes a service behaviour in the Fluence network.
pub trait FCEService {
/// Invokes a module supplying byte array and expecting byte array with some outcome back.
fn call(&mut self, module_name: &str, function_name: &str, arguments: &[IValue]) -> Result<Vec<IValue>, FCEError>;
fn call(
&mut self,
module_name: &str,
function_name: &str,
arguments: &[IValue],
) -> Result<Vec<IValue>, FCEError>;
/// Registers new module in the FCE Service.
fn register_module<S>(

View File

@ -75,11 +75,7 @@ impl FCEModule {
})
}
pub fn call(
&mut self,
function_name: &str,
args: &[IValue],
) -> Result<Vec<IValue>, FCEError> {
pub fn call(&mut self, function_name: &str, args: &[IValue]) -> Result<Vec<IValue>, FCEError> {
use wasmer_wit::interpreter::stack::Stackable;
match self.exports_funcs.get(function_name) {

View File

@ -15,7 +15,6 @@
*/
/// Contains converters of types and values between Wasmer and wasmer_interface_types.
use super::{WType, WValue, IType, IValue};
pub(super) fn wtype_to_itype(ty: &WType) -> IType {

View File

@ -72,7 +72,10 @@ impl WITFunction {
}
/// Creates function from a module import.
pub(super) fn from_import(wit_module: Arc<FCEModule>, func_name: String) -> Result<Self, FCEError> {
pub(super) fn from_import(
wit_module: Arc<FCEModule>,
func_name: String,
) -> Result<Self, FCEError> {
let func_type = wit_module.as_ref().get_func_signature(&func_name)?;
let inputs = func_type.0.clone();
let outputs = func_type.1.clone();

View File

@ -20,9 +20,7 @@ use super::fce_module::FCEModule;
use wasmer_wit::interpreter::wasm;
use super::IAstType;
use wasmer_wit::ast::Interfaces;
use wasmer_wit::interpreter::wasm::structures::{
LocalImportIndex, TypedIndex,
};
use wasmer_wit::interpreter::wasm::structures::{LocalImportIndex, TypedIndex};
use wasmer_core::Instance as WasmerInstance;
use std::collections::HashMap;