Skip to main content

Sensor

Trait Sensor 

Source
pub trait Sensor {
    type Reading;

    // Required method
    fn read(&mut self) -> impl Future<Output = Result<Self::Reading>> + Send;

    // Provided method
    fn map<F, T>(self, select: F) -> Map<Self, F>
       where Self: Sized,
             F: FnMut(Self::Reading) -> T { ... }
}
Expand description

A source of typed readings, such as a thermometer, GPS receiver, or lidar.

Required Associated Types§

Source

type Reading

The value produced by a single read, for example a temperature or a fix.

Required Methods§

Source

fn read(&mut self) -> impl Future<Output = Result<Self::Reading>> + Send

Takes a single reading from the sensor.

§Returns

The next Reading sampled from the sensor.

§Errors

Returns Error::Io if the sensor cannot be read, or Error::Closed if the sensor has been disconnected.

Provided Methods§

Source

fn map<F, T>(self, select: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Reading) -> T,

Wraps this sensor so every reading passes through select first.

This is how a driver that measures several channels feeds a consumer that wants one number: select picks the channel, converts the unit, or combines fields, and the result is a Sensor whose reading is whatever select returns. See Map for an example.

§Arguments
  • select - the function applied to each reading as it is taken.
§Returns

The adapted sensor.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<S, F, T> Sensor for Map<S, F>
where S: Sensor + Send, F: FnMut(S::Reading) -> T + Send,