Skip to main content

AsyncOnePass

Struct AsyncOnePass 

Source
pub struct AsyncOnePass<S: AsyncPatchSink> { /* private fields */ }
Available on crate feature async only.
Expand description

Writes a file to an async sink as its messages arrive, as OnePass does to a sink.

use fit_encoder::*;

async fn record(sink: impl AsyncPatchSink, start: Timestamp) -> Result<(), Error> {
    let mut file = AsyncOnePass::new(sink, Options::new());
    let mut w = file.writer();
    w.start(start, &Device::new(Manufacturer::DEVELOPMENT, 1)).await?;
    w.session(start, Sport::WALKING, SubSport::GENERIC).await?;
    w.record(&Record::new(start).heart_rate(100)).await?;
    w.end(start.checked_add(1).unwrap()).await?;
    file.finish().await.map_err(|_| Error::Sink)?;
    Ok(())
}

Implementations§

Source§

impl<S: AsyncPatchSink> AsyncOnePass<S>

Source

pub fn new(sink: S, options: Options) -> Self

Stages the header, its length to come.

Source

pub fn writer(&mut self) -> AsyncWriter<'_, S>

The writer for the next messages.

Source

pub async fn finish(self) -> Result<S, FinishError<Self, S::Error>>

Writes the file CRC and patches the header’s length in, as OnePass::finish does.

§Errors

As OnePass::finish’s.

Source

pub fn into_sink(self) -> S

The sink, giving up on the file: its header still claims no messages, so readers refuse it, and what was staged is never written.

Trait Implementations§

Source§

impl<S: AsyncPatchSink> Debug for AsyncOnePass<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Forget for AsyncOnePass<S>

§

impl<S> Freeze for AsyncOnePass<S>
where S: Freeze, <S as AsyncSink>::Error: Freeze, &'static [FieldDef]: Freeze,

§

impl<S> Move for AsyncOnePass<S>

§

impl<S> RefUnwindSafe for AsyncOnePass<S>

§

impl<S> Send for AsyncOnePass<S>
where S: Send, <S as AsyncSink>::Error: Send, &'static [FieldDef]: Send,

§

impl<S> Sync for AsyncOnePass<S>
where S: Sync, <S as AsyncSink>::Error: Sync,

§

impl<S> Unpin for AsyncOnePass<S>
where S: Unpin, <S as AsyncSink>::Error: Unpin, &'static [FieldDef]: Unpin,

§

impl<S> UnsafeUnpin for AsyncOnePass<S>
where S: UnsafeUnpin, <S as AsyncSink>::Error: UnsafeUnpin, &'static [FieldDef]: UnsafeUnpin,

§

impl<S> UnwindSafe for AsyncOnePass<S>
where S: UnwindSafe, <S as AsyncSink>::Error: UnwindSafe, &'static [FieldDef]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.