ctrf-rs 0.2.0

A reporter for Common Test Report Format (CTRF) in Rust
Documentation
// crate import(s)
use crate::impl_extra;

// std import(s)
use std::collections::HashMap;

// other import(s)
use serde::{Deserialize, Serialize};
use serde_json::Value;

pub const TOOL_NAME: &str = "ctrf-rs";

/// Tool element for a CTRF report.
/// Corresponds to the spec's ["Tool"](https://www.ctrf.io/docs/specification/tool) object.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Tool {
    name: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    version: Option<String>,
    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
    extra: HashMap<String, Value>,
}

impl Tool {
    /// Creates a `Tool` instance
    pub fn new() -> Self {
        Self {
            name: String::from(TOOL_NAME),
            version: Some(env!("CARGO_PKG_VERSION").into()),
            extra: HashMap::new(),
        }
    }
}

impl Default for Tool {
    fn default() -> Self {
        Self::new()
    }
}

impl_extra!(Tool);