pub async fn write_async<S, E, F>(
sink: S,
options: Options,
source: F,
) -> Result<S, WriteError<S::Error, E>>Available on crate feature
async only.Expand description
Writes the file source describes to an async sink, as write() does to a
sink: header first and CRC last, without seeking, the source run twice.
use fit_encoder::*;
struct Uart;
impl AsyncSink for Uart {
type Error = ();
async fn write(&mut self, bytes: &[u8]) -> Result<(), ()> {
Ok(()) // Await the UART here.
}
}
async fn send(start: Timestamp, hr: &[u8]) -> Result<(), WriteError<(), Error>> {
write_async(Uart, Options::new(), async |w| {
w.start(start, &Device::new(Manufacturer::DEVELOPMENT, 1)).await?;
w.session(start, Sport::RUNNING, SubSport::TREADMILL).await?;
for (s, &bpm) in (0..).zip(hr) {
w.record(&Record::new(start.checked_add(s).unwrap()).heart_rate(bpm)).await?;
}
w.end(start.checked_add(60).unwrap()).await
})
.await?;
Ok(())
}§Errors
As write()’s.