rf_core/
sensor_id.rs

1/// # A virtual representation of a sensor.
2///
3/// `name` is the name of the sensor
4#[derive(PartialEq, Debug, Clone, Eq, Hash)]
5pub struct SensorId {
6    pub(crate) name: String,
7}
8pub fn sensor(name: &str) -> SensorId {
9    SensorId::new(name.to_string())
10}
11
12impl SensorId {
13    /// Given a string, creates a new sensor id.
14    ///
15    /// # Arguments
16    ///
17    /// * `name` - A string representing the name of the sensor.
18    ///
19    /// # Returns
20    ///
21    /// A new sensor id.
22    pub fn new(name: String) -> Self {
23        Self { name }
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use crate::sensor_id::SensorId;
30
31    #[test]
32    fn test_new() {
33        let sensor_id = SensorId::new("foo".to_string());
34        assert_eq!(sensor_id.name, "foo".to_string())
35    }
36}