fundamentum_sdk_mqtt/
device.rs

1//! Fundamentum device representation
2//!
3
4/// Fundamentum Device
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct Device {
7    /// Unique identifier of a device used by the client to recognize his devices.
8    serial: String,
9    /// Identifier of the project to which the device is provisioned into
10    project_id: u64,
11    /// Identifier of the region to which the device is provisioned into
12    region_id: u64,
13    /// Identifier of the registry to which the device is provisioned into
14    registry_id: u64,
15}
16
17impl Device {
18    /// Create a new [`Device`]
19    pub fn new<S: Into<String>>(
20        serial: S,
21        project_id: u64,
22        region_id: u64,
23        registry_id: u64,
24    ) -> Self {
25        Self {
26            serial: serial.into(),
27            project_id,
28            region_id,
29            registry_id,
30        }
31    }
32
33    /// Returns the MQTT client id of this [`Device`].
34    #[must_use]
35    pub fn client_id(&self) -> String {
36        format!(
37            "projects/{}/regions/{}/registries/{}/devices/{}",
38            self.project_id, self.region_id, self.registry_id, self.serial
39        )
40    }
41
42    /// Returns a reference to the serial of this [`Device`].
43    #[must_use]
44    pub fn serial(&self) -> &str {
45        self.serial.as_ref()
46    }
47
48    /// Returns the project id of this [`Device`].
49    #[must_use]
50    pub const fn project_id(&self) -> u64 {
51        self.project_id
52    }
53
54    /// Returns the region id of this [`Device`].
55    #[must_use]
56    pub const fn region_id(&self) -> u64 {
57        self.region_id
58    }
59
60    /// Returns the registry id of this [`Device`].
61    #[must_use]
62    pub const fn registry_id(&self) -> u64 {
63        self.registry_id
64    }
65}