irc_bot/core/
pkg_info.rs

1use super::State;
2
3fn choose(list: &'static [Option<&'static str>]) -> &'static str {
4    list.iter()
5        .filter_map(|&x| x)
6        .find(|s| !s.is_empty() && !s.contains(char::is_control))
7        .unwrap_or(&"<unknown>")
8}
9
10lazy_static! {
11    pub(super) static ref NAME_STR: &'static str = choose(&[option_env!("CARGO_PKG_NAME")]);
12    pub(super) static ref VERSION_STR: &'static str = choose(&[
13        option_env!("IRC_BOT_RS_GIT_VERSION"),
14        option_env!("CARGO_PKG_VERSION"),
15    ]);
16    pub(super) static ref HOMEPAGE_STR: &'static str = choose(&[option_env!("CARGO_PKG_HOMEPAGE")]);
17    pub(super) static ref BRIEF_CREDITS_STRING: String = format!(
18        "Built with <{url}> {ver}",
19        url = HOMEPAGE_STR.deref(),
20        ver = VERSION_STR.deref(),
21    );
22}
23
24impl State {
25    /// Returns a `&str` containing either the name of this crate or the text `"<unknown>"`.
26    pub fn framework_crate_name(&self) -> &'static str {
27        &NAME_STR
28    }
29
30    /// Returns a `&str` containing either version information for the bot framework or the text
31    /// `"<unknown>"`.
32    ///
33    /// This version information is intended for display only, and is not necessarily in [SemVer]
34    /// format or otherwise intended as machine-readable.
35    ///
36    /// [SemVer]: <https://semver.org>
37    pub fn framework_version_str(&self) -> &'static str {
38        &VERSION_STR
39    }
40
41    /// Returns a `&str` containing either a [Uniform Resource Locator (URL)][URI] for a Web page
42    /// containing information about the bot framework, or the text `"<unknown>"`.
43    ///
44    /// [URI]: <https://tools.ietf.org/html/rfc3986>
45    pub fn framework_homepage_url_str(&self) -> &'static str {
46        &HOMEPAGE_STR
47    }
48}