1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
use std::collections::HashMap; use crate::idl; use super::errors::ValidationError; use super::namespace::Namespace; use super::r#type::Type; use super::typemap::TypeMap; pub struct Service { pub name: String, pub methods: Vec<Method>, } pub struct Method { pub name: String, pub input: Option<Type>, pub output: Option<Type>, } impl Service { pub(crate) fn from_idl( iservice: &idl::Service, ns: &Namespace, builtin_types: &HashMap<String, String>, ) -> Self { Self { name: iservice.name.clone(), methods: iservice .methods .iter() .map(|imethod| Method { name: imethod.name.clone(), input: imethod .input .as_ref() .map(|x| Type::from_idl(x, ns, &builtin_types)), output: imethod .output .as_ref() .map(|x| Type::from_idl(x, ns, &builtin_types)), }) .collect(), } } pub(crate) fn resolve(&mut self, type_map: &TypeMap) -> Result<(), ValidationError> { for method in self.methods.iter_mut() { if let Some(input) = &mut method.input { input.resolve(type_map)?; } if let Some(output) = &mut method.output { output.resolve(type_map)?; } } Ok(()) } }