ctrf_rs/
tool.rs

1// crate import(s)
2use crate::impl_extra;
3
4// std import(s)
5use std::collections::HashMap;
6
7// other import(s)
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10
11pub const TOOL_NAME: &str = "ctrf-rs";
12
13/// Tool element for a CTRF report.
14/// Corresponds to the spec's ["Tool"](https://www.ctrf.io/docs/specification/tool) object.
15#[derive(Serialize, Deserialize, Debug, PartialEq)]
16#[serde(rename_all = "camelCase")]
17pub struct Tool {
18    name: String,
19    #[serde(default, skip_serializing_if = "Option::is_none")]
20    version: Option<String>,
21    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
22    extra: HashMap<String, Value>,
23}
24
25impl Tool {
26    /// Creates a `Tool` instance
27    pub fn new() -> Self {
28        Self {
29            name: String::from(TOOL_NAME),
30            version: Some(env!("CARGO_PKG_VERSION").into()),
31            extra: HashMap::new(),
32        }
33    }
34}
35
36impl Default for Tool {
37    fn default() -> Self {
38        Self::new()
39    }
40}
41
42impl_extra!(Tool);