use HashMap for functions in get_interface (#7)

This commit is contained in:
vms
2020-06-30 19:23:43 +03:00
committed by GitHub
parent 46ef013f7e
commit 80afea2094
4 changed files with 43 additions and 16 deletions

View File

@@ -22,10 +22,10 @@ use std::collections::HashMap;
/// Represent a function type inside FCE.
#[derive(Debug, serde::Serialize)]
pub struct FCEFunction<'a> {
pub struct FCEFunctionSignature<'a> {
pub name: &'a str,
pub inputs: &'a Vec<IType>,
pub outputs: &'a Vec<IType>,
pub input_types: &'a Vec<IType>,
pub output_types: &'a Vec<IType>,
}
/// The base struct of the Fluence Compute Engine.
@@ -87,7 +87,7 @@ impl FCE {
}
/// Return function signatures of all loaded info FCE modules with their names.
pub fn interface(&self) -> impl Iterator<Item = (&str, Vec<FCEFunction<'_>>)> {
pub fn interface(&self) -> impl Iterator<Item = (&str, Vec<FCEFunctionSignature<'_>>)> {
self.modules.iter().map(|(module_name, module)| {
(
module_name.as_str(),
@@ -100,20 +100,20 @@ impl FCE {
pub fn module_interface<S: AsRef<str>>(
&self,
module_name: S,
) -> Result<Vec<FCEFunction<'_>>, FCEError> {
) -> Result<Vec<FCEFunctionSignature<'_>>, FCEError> {
match self.modules.get(module_name.as_ref()) {
Some(module) => Ok(Self::get_module_function_signatures(module)),
None => Err(FCEError::NoSuchModule),
}
}
fn get_module_function_signatures(module: &FCEModule) -> Vec<FCEFunction<'_>> {
fn get_module_function_signatures(module: &FCEModule) -> Vec<FCEFunctionSignature<'_>> {
module
.get_exports_signatures()
.map(|(name, inputs, outputs)| FCEFunction {
.map(|(name, input_types, output_types)| FCEFunctionSignature {
name,
inputs,
outputs,
input_types,
output_types,
})
.collect::<Vec<_>>()
}