Creating efficient I/O-based applications is tricky—they have to provide exclusive access to a resource as quickly as possible and as often as required. It's a resource scheduling problem. The basis of solving this type of problem is to handle and queue requests, as with reading a sensor value.
Efficiently reading hardware sensors
How to do it...
You can use I/O loops to read things efficiently in a few steps:
- Create a binary project: cargo new reading-hardware.
- Open the folder in VS Code and create a src/sensor.rs file to add the code from the Creating I2C device drivers recipe:
use std::io;
use rand::prelude::*;
type Result<T> = std::result::Result<T, io::Error>;
pub trait Thermometer {
fn temp_celsius...