ascom_alpaca/api/
server_info.rs

1use serde::{Deserialize, Serialize};
2use std::borrow::Cow;
3
4#[derive(Debug, Serialize, Deserialize)]
5pub(crate) struct ConfiguredDevice<DeviceType> {
6    #[serde(rename = "DeviceName")]
7    pub(crate) name: String,
8    #[serde(rename = "DeviceType")]
9    pub(crate) ty: DeviceType,
10    #[serde(rename = "DeviceNumber")]
11    pub(crate) number: usize,
12    #[serde(rename = "UniqueID")]
13    pub(crate) unique_id: String,
14}
15
16/// General information about the server.
17#[derive(Debug, Serialize, Deserialize, derive_more::Display)]
18#[display("{server_name} v{manufacturer_version} by {manufacturer}")]
19#[serde(rename_all = "PascalCase")]
20pub struct ServerInfo {
21    /// Server name.
22    pub server_name: Cow<'static, str>,
23    /// Manufacturer name.
24    pub manufacturer: Cow<'static, str>,
25    /// Manufacturer version.
26    pub manufacturer_version: Cow<'static, str>,
27    /// Server location.
28    pub location: Cow<'static, str>,
29}
30
31// Using macro namespacing hack from https://users.rust-lang.org/t/how-to-namespace-a-macro-rules-macro-within-a-module-or-macro-export-it-without-polluting-the-top-level-namespace/63779/5?u=rreverser.
32#[doc(hidden)]
33#[macro_export]
34macro_rules! CargoServerInfo_1bc8c806_8cb9_4aaf_b57a_8f94c4d1b59d {
35    () => {
36        const {
37            use std::borrow::Cow;
38
39            $crate::api::ServerInfo {
40                server_name: Cow::Borrowed(env!("CARGO_PKG_NAME")),
41                manufacturer: Cow::Borrowed(env!("CARGO_PKG_AUTHORS")),
42                manufacturer_version: Cow::Borrowed(env!("CARGO_PKG_VERSION")),
43                location: {
44                    // Technically this field should be a physical location,
45                    // but repository homepage seems better than nothing.
46                    let homepage = env!("CARGO_PKG_HOMEPAGE");
47                    Cow::Borrowed(if homepage.is_empty() {
48                        "Unknown"
49                    } else {
50                        homepage
51                    })
52                },
53            }
54        }
55    };
56}
57
58/// A helper that constructs a [`ServerInfo`](crate::api::ServerInfo) instance populated with metadata from `Cargo.toml`.
59#[doc(inline)]
60pub use CargoServerInfo_1bc8c806_8cb9_4aaf_b57a_8f94c4d1b59d as CargoServerInfo;