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