1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/// # A virtual representation of a sensor.
///
/// `name` is the name of the sensor
#[derive(PartialEq, Debug, Clone, Eq, Hash)]
pub struct SensorId {
    pub(crate) name: String,
}
pub fn sensor(name: &str) -> SensorId {
    SensorId::new(name.to_string())
}

impl SensorId {
    /// Given a string, creates a new sensor id.
    ///
    /// # Arguments
    ///
    /// * `name` - A string representing the name of the sensor.
    ///
    /// # Returns
    ///
    /// A new sensor id.
    pub fn new(name: String) -> Self {
        Self { name }
    }
}

#[cfg(test)]
mod tests {
    use crate::sensor_id::SensorId;

    #[test]
    fn test_new() {
        let sensor_id = SensorId::new("foo".to_string());
        assert_eq!(sensor_id.name, "foo".to_string())
    }
}