1 use super::graph::Graph; 2 use super::parse_util::UnitParseUtil; 3 4 use crate::error::parse_error::ParseError; 5 use crate::manager::UnitManager; 6 7 pub struct ServiceParser; 8 9 impl ServiceParser { 10 /// @brief 解析Service类型Unit的 11 /// 12 /// 从path解析Service类型Unit 13 /// 14 /// @param path 需解析的文件路径 15 /// 16 /// @return 成功则返回Ok(id),否则返回Err parse(path: &str) -> Result<usize, ParseError>17 pub fn parse(path: &str) -> Result<usize, ParseError> { 18 //预先检查是否存在循环依赖 19 let mut graph = Graph::construct_graph(path.to_string())?; 20 let ret = graph.topological_sort()?; 21 for p in ret { 22 UnitParseUtil::parse_unit_no_type(&p)?; 23 } 24 25 let result = UnitManager::get_id_with_path(path).unwrap(); 26 27 return Ok(result); 28 } 29 } 30