Skip to main content

pedant_types/
profile.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{Capability, CapabilityFinding};
4
5/// A collection of capability findings for a crate.
6#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
7pub struct CapabilityProfile {
8    /// All findings from the analysis.
9    pub findings: Vec<CapabilityFinding>,
10}
11
12impl CapabilityProfile {
13    /// Returns deduplicated, sorted set of capabilities present in the profile.
14    /// Recomputes on each call; callers needing repeated access should cache the result.
15    pub fn capabilities(&self) -> Vec<Capability> {
16        let mut caps: Vec<Capability> = self.findings.iter().map(|f| f.capability).collect();
17        caps.sort();
18        caps.dedup();
19        caps
20    }
21
22    /// Returns findings filtered to a specific capability.
23    pub fn findings_for(&self, capability: Capability) -> Vec<&CapabilityFinding> {
24        self.findings
25            .iter()
26            .filter(|f| f.capability == capability)
27            .collect()
28    }
29}