Struct Measurement

Source
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§

Source§

impl<'a> Measurement<'a>

Source

pub fn new(data: Option<SensorData>, error: Option<&'a str>) -> Measurement<'_>

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.
Source

pub fn get_data(&self) -> Option<SensorData>

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

Source

pub fn get_error(&self) -> Option<&'a str>

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

Source

pub fn has_data(&self) -> bool

Check if the measurement has data.

Source

pub fn has_error(&self) -> bool

Check if the measurement has an error.

Auto Trait Implementations§

§

impl<'a> Freeze for Measurement<'a>

§

impl<'a> RefUnwindSafe for Measurement<'a>

§

impl<'a> Send for Measurement<'a>

§

impl<'a> Sync for Measurement<'a>

§

impl<'a> Unpin for Measurement<'a>

§

impl<'a> UnwindSafe for Measurement<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.