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§
Required Methods§
Provided Methods§
Sourcefn map<F, T>(self, select: F) -> Map<Self, F>
fn map<F, T>(self, select: F) -> Map<Self, F>
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".