sync_readme/
config.rs

1use std::collections::BTreeMap;
2
3use camino::Utf8PathBuf;
4
5#[derive(serde_derive::Deserialize, Debug, Clone)]
6#[serde(default, deny_unknown_fields)]
7pub struct Metadata {
8    #[serde(alias = "rustdoc-mappings")]
9    pub rustdoc_mappings: BTreeMap<String, String>,
10    #[serde(alias = "rustdoc-html-root-url")]
11    pub rustdoc_html_root_url: Option<String>,
12    #[serde(alias = "badge-style")]
13    pub badge_style: String,
14    pub badges: Badges,
15    #[serde(alias = "custom-badges")]
16    pub custom_badges: Vec<CustomBadge>,
17}
18
19impl Default for Metadata {
20    fn default() -> Self {
21        Self {
22            badge_style: "flat-square".to_string(),
23            rustdoc_html_root_url: Default::default(),
24            badges: Default::default(),
25            rustdoc_mappings: Default::default(),
26            custom_badges: Default::default(),
27        }
28    }
29}
30
31#[derive(serde_derive::Deserialize, Debug, Default, Clone)]
32#[serde(deny_unknown_fields)]
33pub struct CustomBadge {
34    pub name: String,
35    pub url: String,
36    #[serde(default)]
37    pub link: Option<String>,
38}
39
40#[derive(serde_derive::Deserialize, Debug, Default, Clone)]
41#[serde(default, deny_unknown_fields)]
42pub struct Badges {
43    #[serde(alias = "docs-rs")]
44    pub docs_rs: bool,
45    pub license: bool,
46    #[serde(alias = "crates-io")]
47    pub crates_io: CratesIo,
48    pub codecov: Codecov,
49}
50
51#[derive(serde_derive::Deserialize, Debug, Clone)]
52#[serde(untagged)]
53pub enum CratesIo {
54    Simple(bool),
55    Complex {
56        #[serde(default)]
57        release: bool,
58        #[serde(default)]
59        size: bool,
60        #[serde(default)]
61        downloads: bool,
62    },
63}
64
65impl CratesIo {
66    pub fn release(&self) -> bool {
67        match self {
68            Self::Simple(t) => *t,
69            Self::Complex { release, .. } => *release,
70        }
71    }
72
73    pub fn size(&self) -> bool {
74        match self {
75            Self::Simple(t) => *t,
76            Self::Complex { size, .. } => *size,
77        }
78    }
79
80    pub fn downloads(&self) -> bool {
81        match self {
82            Self::Simple(t) => *t,
83            Self::Complex { downloads, .. } => *downloads,
84        }
85    }
86}
87
88impl Default for CratesIo {
89    fn default() -> Self {
90        Self::Simple(false)
91    }
92}
93
94#[derive(serde_derive::Deserialize, Debug, Clone)]
95#[serde(untagged)]
96pub enum Codecov {
97    Simple(bool),
98    Complex {
99        component: String,
100    },
101}
102
103impl Default for Codecov {
104    fn default() -> Self {
105        Self::Simple(false)
106    }
107}
108
109pub struct Package {
110    pub name: String,
111    pub version: String,
112    pub license: Option<String>,
113    pub metadata: Metadata,
114    pub rustdoc_json: Utf8PathBuf,
115}