Skip to main content

human_panic/
metadata.rs

1use std::borrow::Cow;
2
3/// A convenient metadata struct that describes a crate
4///
5/// See [`metadata!`][crate::metadata!]
6pub struct Metadata {
7    pub(crate) name: Cow<'static, str>,
8    pub(crate) version: Cow<'static, str>,
9    pub(crate) authors: Option<Cow<'static, str>>,
10    pub(crate) homepage: Option<Cow<'static, str>>,
11    pub(crate) repository: Option<Cow<'static, str>>,
12    pub(crate) support: Option<Cow<'static, str>>,
13}
14
15impl Metadata {
16    /// See [`metadata!`][crate::metadata!]
17    pub fn new(name: impl Into<Cow<'static, str>>, version: impl Into<Cow<'static, str>>) -> Self {
18        Self {
19            name: name.into(),
20            version: version.into(),
21            authors: None,
22            homepage: None,
23            repository: None,
24            support: None,
25        }
26    }
27
28    /// The list of authors of the crate
29    pub fn authors(mut self, value: impl Into<Cow<'static, str>>) -> Self {
30        let value = value.into();
31        if !value.is_empty() {
32            self.authors = value.into();
33        }
34        self
35    }
36
37    /// The URL of the crate's website
38    pub fn homepage(mut self, value: impl Into<Cow<'static, str>>) -> Self {
39        let value = value.into();
40        if !value.is_empty() {
41            self.homepage = value.into();
42        }
43        self
44    }
45
46    /// The URL of the crate's repository
47    pub fn repository(mut self, value: impl Into<Cow<'static, str>>) -> Self {
48        let value = value.into();
49        if !value.is_empty() {
50            self.repository = value.into();
51        }
52        self
53    }
54
55    /// The support information
56    pub fn support(mut self, value: impl Into<Cow<'static, str>>) -> Self {
57        let value = value.into();
58        if !value.is_empty() {
59            self.support = value.into();
60        }
61        self
62    }
63}