pub struct Measurement<'a> { /* private fields */ }
Expand description

Data container for a DHT sensor measurement that contains either an error or data.

use dht_logger::{Measurement, SensorData};
// Example test data
let error = "test";
let data = SensorData {
    temperature: 0.0,
    humidity: 0.0,
    heat_index: 0.0,
};

// Create a measurement containing an error
let measurement = Measurement::new(None, Some(error));
assert!(measurement.get_data().is_none());
assert!(measurement.get_error().is_some());
assert_eq!(measurement.get_error().unwrap(), error);

// Create a measurement containing data
let measurement = Measurement::new(Some(data), None);
assert!(measurement.get_data().is_some());
assert!(measurement.get_error().is_none());
assert_eq!(measurement.get_data().unwrap(), data);

Implementations

Create a new measurement of a DHT sensor.

Args:

  • data: Sensor data from one DHT sensor.
  • error: Error indicating a failure to read a DHT sensor.

Get the data contained by the measurement, if it exists.

Get the error contained by the measurement, if it exists.

Check if the measurement has data.

Check if the measurement has an error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.