diff --git a/src/device.rs b/src/device.rs index ad95be6..a1ae198 100644 --- a/src/device.rs +++ b/src/device.rs @@ -9,7 +9,7 @@ use crate::container::{Container, Containerized}; /// Basic interface for GPIO device metadata pub trait Device { - fn get_info(&self) -> &DeviceInfo; + fn get_metadata(&self) -> &DeviceMetadata; fn name(&self) -> String; fn id(&self) -> i32; } @@ -55,7 +55,7 @@ pub trait Sensor: Device { impl std::fmt::Debug for dyn Sensor { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "Sensor {{ name: {}, id: {}, info: {}", self.name(), self.id(), self.get_info()) + write!(f, "Sensor {{ name: {}, id: {}, info: {}", self.name(), self.id(), self.get_metadata()) } } @@ -86,8 +86,7 @@ pub trait Calibrated { /// let info = crate::DeviceInfo::new(name, version_id, sensor_id, kind, min_value, max_value, resolution, min_delay); /// ``` #[derive(Debug, Clone, PartialEq)] -// TODO: rename to `DeviceMetadata` -pub struct DeviceInfo { +pub struct DeviceMetadata { // TODO: what changes should be made? Dedicated struct for number space? Should `min_delay` be moved to `Device`? pub name: String, pub version_id: i32, @@ -101,7 +100,7 @@ pub struct DeviceInfo { min_delay: Duration, } -impl DeviceInfo { +impl DeviceMetadata { /// Creates a new instance of `DeviceInfo` /// /// # Arguments @@ -120,7 +119,7 @@ impl DeviceInfo { /// A new instance with given specified parameters pub fn new(name: String, version_id: i32, sensor_id: i32, kind: io::IOKind, min_value: T, max_value: T, resolution: T, min_delay: Duration) -> Self { - DeviceInfo { + DeviceMetadata { name, version_id, sensor_id, kind, min_value, max_value, resolution, min_delay, @@ -128,7 +127,7 @@ impl DeviceInfo { } } -impl std::fmt::Display for DeviceInfo { +impl std::fmt::Display for DeviceMetadata { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "Device Info {{ Kind: {}, Min. Delay: {} }}", self.kind, self.min_delay.to_string()) } @@ -139,7 +138,7 @@ impl std::fmt::Display for DeviceInfo { /// Objects are stored as `Box>` impl Containerized>, K> for dyn Sensor where T: std::fmt::Debug, - K: std::hash::Hash + K: std::hash::Hash + Eq { fn container() -> Container>, K> { Container::>, K>::new() diff --git a/src/io.rs b/src/io.rs index a224430..d1213a2 100644 --- a/src/io.rs +++ b/src/io.rs @@ -6,7 +6,7 @@ use crate::device; use crate::container::{Container, Containerized}; /// Defines sensor type. Used to classify data along with `IOData`. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum IOKind { Light, Pressure, @@ -82,7 +82,7 @@ impl IOEvent { /// /// ``` pub fn create( device: &impl device::Device, timestamp: DateTime, value: T ) -> Self { - let info = &device.get_info(); + let info = device.get_metadata(); let version_id = info.version_id; let sensor_id = info.sensor_id; let data = IOData { diff --git a/src/sensors/ph.rs b/src/sensors/ph.rs index e8b4af1..b4f4570 100644 --- a/src/sensors/ph.rs +++ b/src/sensors/ph.rs @@ -4,7 +4,7 @@ use crate::{device, io, units::Ph}; #[derive(Debug, Clone)] pub struct MockPhSensor { - info: device::DeviceInfo + metadata: device::DeviceMetadata } /** Represents a mock pH sensor. @@ -26,12 +26,12 @@ impl MockPhSensor { let max_value = Ph(14.0); let resolution = Ph(0.1); - let info: device::DeviceInfo = device::DeviceInfo::new(name, version_id, sensor_id, - kind, min_value, max_value, resolution, - min_delay); + let metadata: device::DeviceMetadata = device::DeviceMetadata::new(name, version_id, sensor_id, + kind, min_value, max_value, resolution, + min_delay); MockPhSensor { - info + metadata } } } @@ -39,14 +39,14 @@ impl MockPhSensor { // Implement traits impl device::Device for MockPhSensor { - fn get_info(&self) -> &device::DeviceInfo { - &self.info + fn get_metadata(&self) -> &device::DeviceMetadata { + &self.metadata } fn name(&self) -> String { - self.info.name.clone() + self.metadata.name.clone() } fn id(&self) -> i32 { - self.info.sensor_id + self.metadata.sensor_id } }