diff --git a/rust-code-analysis-cli/src/web/metrics.rs b/rust-code-analysis-cli/src/web/metrics.rs index 055fa4c05..117e405b3 100644 --- a/rust-code-analysis-cli/src/web/metrics.rs +++ b/rust-code-analysis-cli/src/web/metrics.rs @@ -13,10 +13,10 @@ pub struct WebMetricsPayload { } #[derive(Debug, Serialize)] -pub struct WebMetricsResponse<'a> { +pub struct WebMetricsResponse { pub id: String, pub language: String, - pub spaces: Option>, + pub spaces: Option, } #[derive(Debug, Deserialize)] diff --git a/src/output/dump_metrics.rs b/src/output/dump_metrics.rs index d2d59e3cb..cf44ebf09 100644 --- a/src/output/dump_metrics.rs +++ b/src/output/dump_metrics.rs @@ -65,7 +65,7 @@ fn dump_space( write!(stdout, "{}: ", space.kind)?; color!(stdout, Cyan, true); - write!(stdout, "{}", space.name.map_or("", |name| name))?; + write!(stdout, "{}", space.name.as_ref().map_or("", |name| &name))?; color!(stdout, Red, true); writeln!(stdout, " (@{})", space.start_line)?; diff --git a/src/spaces.rs b/src/spaces.rs index e797902ae..484b0e30d 100644 --- a/src/spaces.rs +++ b/src/spaces.rs @@ -115,12 +115,12 @@ impl CodeMetrics { /// Function space data. #[derive(Debug, Clone, Serialize)] -pub struct FuncSpace<'a> { +pub struct FuncSpace { /// The name of a function space /// /// If `None`, an error is occured in parsing /// the name of a function space - pub name: Option<&'a str>, + pub name: Option, /// The first line of a function space pub start_line: usize, /// The last line of a function space @@ -128,13 +128,13 @@ pub struct FuncSpace<'a> { /// The space kind pub kind: SpaceKind, /// All subspaces contained in a function space - pub spaces: Vec>, + pub spaces: Vec, /// All metrics of a function space pub metrics: CodeMetrics, } -impl<'a> FuncSpace<'a> { - fn new(node: &Node<'a>, code: &'a [u8], kind: SpaceKind) -> Self { +impl FuncSpace { + fn new(node: &Node, code: &[u8], kind: SpaceKind) -> Self { let (start_position, end_position) = match kind { SpaceKind::Unit => { if node.object().child_count() == 0 { @@ -152,7 +152,7 @@ impl<'a> FuncSpace<'a> { ), }; Self { - name: T::get_func_space_name(&node, code), + name: T::get_func_space_name(&node, code).map(|name| name.to_string()), spaces: Vec::new(), metrics: CodeMetrics::default(), kind, @@ -196,7 +196,7 @@ fn finalize<'a, T: ParserTrait>(state_stack: &mut Vec>, diff_level: us #[derive(Debug, Clone)] struct State<'a> { - space: FuncSpace<'a>, + space: FuncSpace, halstead_maps: HalsteadMaps<'a>, } @@ -223,7 +223,7 @@ struct State<'a> { /// metrics(&parser, &path).unwrap(); /// # } /// ``` -pub fn metrics<'a, T: ParserTrait>(parser: &'a T, path: &'a PathBuf) -> Option> { +pub fn metrics<'a, T: ParserTrait>(parser: &'a T, path: &'a PathBuf) -> Option { let code = parser.get_code(); let node = parser.get_root(); let mut cursor = node.object().walk(); @@ -284,7 +284,7 @@ pub fn metrics<'a, T: ParserTrait>(parser: &'a T, path: &'a PathBuf) -> Option(&mut state_stack, std::usize::MAX); state_stack.pop().map(|mut state| { - state.space.name = path.to_str(); + state.space.name = path.to_str().map(|name| name.to_string()); state.space }) }