pub struct Map<S, F> { /* private fields */ }Expand description
A sensor whose readings pass through a function before they are returned.
Created by Sensor::map. The function runs on every read, so it can select one
channel of a multi-channel measurement, convert a unit, or fold several fields into
one value.
§Examples
use pamoja_core::{Result, Sensor};
struct Climate;
impl Sensor for Climate {
type Reading = (f32, f32);
async fn read(&mut self) -> Result<(f32, f32)> {
Ok((21.5, 48.0))
}
}
let mut humidity = Climate.map(|(_, humidity)| humidity);
assert_eq!(humidity.read().await?, 48.0);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<S, F> Freeze for Map<S, F>
impl<S, F> RefUnwindSafe for Map<S, F>where
S: RefUnwindSafe,
F: RefUnwindSafe,
impl<S, F> Send for Map<S, F>
impl<S, F> Sync for Map<S, F>
impl<S, F> Unpin for Map<S, F>
impl<S, F> UnsafeUnpin for Map<S, F>where
S: UnsafeUnpin,
F: UnsafeUnpin,
impl<S, F> UnwindSafe for Map<S, F>where
S: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more