ctrf_rs/test/
attachment.rs

1// crate import(s)
2use crate::impl_extra;
3
4// std import(s)
5use std::{collections::HashMap, path::PathBuf};
6
7// other import(s)
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10
11/// Attachment element for a CTRF report.
12/// Corresponds to the spec's ["Attachment"](https://www.ctrf.io/docs/specification/test#attachment-object) object.
13#[derive(Deserialize, Serialize, Debug, PartialEq)]
14#[serde(rename_all = "camelCase")]
15pub struct Attachment {
16    /// Required
17    pub name: String,
18    /// Required
19    pub content_type: String,
20    /// Required
21    pub path: PathBuf,
22    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
23    extra: HashMap<String, Value>,
24}
25
26impl Attachment {
27    /// Creates an `Attachment` instance with the provided arguments and empty `extra`
28    pub fn new(name: String, content_type: String, path: PathBuf) -> Self {
29        Self {
30            name,
31            content_type,
32            path,
33            extra: HashMap::new(),
34        }
35    }
36}
37
38impl_extra!(Attachment);