mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
use HashMap for functions in get_interface (#7)
This commit is contained in:
parent
46ef013f7e
commit
80afea2094
@ -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<_>>()
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ mod misc;
|
||||
|
||||
pub use config::FCEModuleConfig;
|
||||
pub use engine::FCE;
|
||||
pub use engine::FCEFunction;
|
||||
pub use engine::FCEFunctionSignature;
|
||||
pub use errors::FCEError;
|
||||
pub use module::IValue;
|
||||
pub use module::IType;
|
||||
|
@ -28,6 +28,7 @@ use fce::FCEModuleConfig;
|
||||
use std::convert::TryInto;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use crate::faas_interface::FaaSFunctionSignature;
|
||||
|
||||
// TODO: remove and use mutex instead
|
||||
unsafe impl Send for FluenceFaaS {}
|
||||
@ -92,7 +93,7 @@ impl FluenceFaaS {
|
||||
if !path.is_dir() {
|
||||
let module_name = path
|
||||
.file_name()
|
||||
.ok_or(IOError(format!("No file name in path {:?}", path)))?
|
||||
.ok_or_else(|| IOError(format!("No file name in path {:?}", path)))?
|
||||
.to_os_string()
|
||||
.into_string()
|
||||
.map_err(|name| IOError(format!("invalid file name: {:?}", name)))?;
|
||||
@ -137,7 +138,25 @@ impl FluenceFaaS {
|
||||
|
||||
/// Return all export functions (name and signatures) of loaded on a startup modules.
|
||||
pub fn get_interface(&self) -> FaaSInterface {
|
||||
let modules = self.fce.interface().collect();
|
||||
let modules = self
|
||||
.fce
|
||||
.interface()
|
||||
.map(|(name, signatures)| {
|
||||
let signatures = signatures
|
||||
.iter()
|
||||
.map(|f| {
|
||||
(
|
||||
f.name,
|
||||
FaaSFunctionSignature {
|
||||
input_types: f.input_types,
|
||||
output_types: f.output_types,
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
(name, signatures)
|
||||
})
|
||||
.collect();
|
||||
|
||||
FaaSInterface { modules }
|
||||
}
|
||||
|
@ -14,13 +14,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use super::IType;
|
||||
use serde::Serialize;
|
||||
|
||||
use std::fmt;
|
||||
use std::collections::HashMap;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct FaaSInterface<'a> {
|
||||
pub modules: HashMap<&'a str, Vec<fce::FCEFunction<'a>>>,
|
||||
pub modules: HashMap<&'a str, HashMap<&'a str, FaaSFunctionSignature<'a>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct FaaSFunctionSignature<'a> {
|
||||
pub input_types: &'a Vec<IType>,
|
||||
pub output_types: &'a Vec<IType>,
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for FaaSInterface<'a> {
|
||||
@ -28,11 +36,11 @@ impl<'a> fmt::Display for FaaSInterface<'a> {
|
||||
for (name, functions) in self.modules.iter() {
|
||||
writeln!(f, "{}", *name)?;
|
||||
|
||||
for function in functions.iter() {
|
||||
for (name, signature) in functions.iter() {
|
||||
writeln!(
|
||||
f,
|
||||
" pub fn {}({:?}) -> {:?}",
|
||||
function.name, function.inputs, function.outputs
|
||||
name, signature.input_types, signature.output_types
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user