Skip to main content

Writer

Struct Writer 

Source
pub struct Writer<'a> { /* private fields */ }
Expand description

Writes the messages of one file, in order. write() and size() hand one to the source; OnePass::writer gives one too, so a function taking a &mut Writer serves both.

Implementations§

Source§

impl Writer<'_>

Source

pub fn start(&mut self, t: Timestamp, creator: &Device<'_>) -> Result<(), Error>

Starts the activity at t, recorded by creator. The timer starts with the first session.

§Errors

Error::OutOfOrder if it has started already; see Error.

Source

pub fn device(&mut self, device: &Device<'_>) -> Result<(), Error>

Writes a sensor the activity used, as the next device_index after the creator’s.

§Errors

Error::OutOfOrder outside the activity, Error::IndexFull after 254 sensors; see Error.

Source

pub fn session( &mut self, t: Timestamp, sport: Sport, sub_sport: SubSport, ) -> Result<(), Error>

Starts a session of sport at t, ending the one before it there: the next leg of a multisport activity, or a transition between legs. Writer::leg starts one with a name, or moved to by hand.

§Errors

Error::OutOfRange for lap_swimming, as a pool swim starts with Writer::pool_swim; see Error.

Source

pub fn pool_swim(&mut self, t: Timestamp, pool: Pool) -> Result<(), Error>

Starts a pool swim at t in pool, as Writer::session starts any other: its distance is the pool’s length for each length swum, from Writer::length.

§Errors

Error::OutOfRange for a pool of no length; see Error.

Source

pub fn leg(&mut self, t: Timestamp, leg: &Leg<'_>) -> Result<(), Error>

Starts the session leg describes at t, ending the one before it there, as Writer::session and Writer::pool_swim do.

§Errors

Error::OutOfRange for lap_swimming without a pool, a pool of no length or a name holding a NUL, Error::StringTooLong for a name too long, Error::OutOfOrder for a first leg moved to by hand; see Error.

Source

pub fn record(&mut self, record: &Record) -> Result<(), Error>

Writes a record in the current session.

§Errors

Error::OutOfOrder outside a session, Error::Paused while the timer is paused, Error::DistanceWentBack for a total distance below one already written; see Error.

Source

pub fn record_with( &mut self, record: &Record, extras: &[Extra<'_>], ) -> Result<(), Error>

Writes a record with fields besides those Record models: developer fields, from RecordField::value, and raw fields, from RawField. A raw field may not be one the encoder writes: those Record sets, the timestamp, or another form of one, compressed_speed_distance (8), enhanced_speed (73) and enhanced_altitude (78).

§Errors

Those of Writer::record; Error::Undeclared for a field this file did not declare, Error::Duplicate for one given twice, Error::Reserved for a raw field the encoder writes, Error::TooMany past RAW_FIELDS_MAX raw fields.

Source

pub fn lap(&mut self, t: Timestamp) -> Result<(), Error>

Ends the current lap at t, by hand, and starts the next.

§Errors

Error::OutOfOrder outside a session or during a rest in a pool swim; see Error.

Source

pub fn lap_by(&mut self, t: Timestamp, trigger: LapTrigger) -> Result<(), Error>

Writer::lap, for a lap that trigger ended, such as the device’s automatic lap every kilometre.

§Errors

As Writer::lap.

Source

pub fn pause(&mut self, t: Timestamp) -> Result<(), Error>

Pauses the timer at t.

§Errors

Error::OutOfOrder before the first session or if it is paused already; see Error.

Source

pub fn resume(&mut self, t: Timestamp) -> Result<(), Error>

Resumes the timer at t.

§Errors

Error::OutOfOrder before the first session or if it is running; see Error.

Source

pub fn length(&mut self, t: Timestamp, length: &Length) -> Result<(), Error>

Ends a length of the pool at t, swum since the last length, rest or lap ended, or the pool swim started.

§Errors

Error::OutOfOrder outside a pool swim or during a rest, Error::Paused while the timer is paused, Error::IndexFull after 4,095 lengths; see Error.

Source

pub fn set(&mut self, t: Timestamp, set: &Set) -> Result<(), Error>

Writes a strength set that ends at t, done since the last set, rest or lap ended, or the session started.

§Errors

Error::OutOfOrder outside a training or HIIT session or during a rest, Error::Paused while the timer is paused, Error::IndexFull after 4,095 sets; see Error.

Source

pub fn rest(&mut self, t: Timestamp) -> Result<(), Error>

Starts a rest at t, which Writer::end_rest ends. In a pool swim the lap of lengths before it ends here, and the rest is an idle length in a lap of its own; in a training or HIIT session it is a rest between strength sets.

§Errors

Error::OutOfOrder outside a pool swim or a training or HIIT session, or during a rest; see Error.

Source

pub fn end_rest(&mut self, t: Timestamp) -> Result<(), Error>

Ends the rest at t.

§Errors

Error::OutOfOrder outside a rest, Error::IndexFull after 4,095 lengths or sets; see Error.

Source

pub fn beat_intervals_ms(&mut self, intervals: &[u16]) -> Result<(), Error>

Adds the intervals between heartbeats, in milliseconds, as they arrive; a beat’s interval ends it. They are written five to a hrv message, and before the next record, so each follows the record it came after; they are kept while the timer is paused, as their sum is their only clock.

§Errors

Error::OutOfOrder outside the activity, Error::OutOfRange for 65,535; see Error.

Source

pub fn beat_intervals_1024ths(&mut self, intervals: &[u16]) -> Result<(), Error>

Writer::beat_intervals_ms, from intervals in 1/1024 s, as a Bluetooth heart rate sensor gives them; each is rounded to the millisecond.

§Errors

Error::OutOfOrder outside the activity; see Error.

Source

pub fn end(&mut self, t: Timestamp) -> Result<(), Error>

Ends the activity at t: the timer stops, and the last lap, the last session and the activity are written.

§Errors

Error::OutOfOrder if no session has started; see Error.

Source§

impl Writer<'_>

Source

pub fn developer(&mut self, developer: &Developer) -> Result<Dev, Error>

Declares a developer, writing its developer_data_id; its fields are then described with Writer::declare. The first is developer_data_index 0, the next 1, and so on.

§Errors

Error::OutOfOrder outside the activity, Error::Duplicate for an application declared already, Error::TooMany past DEVELOPERS_MAX; see Error.

Source

pub fn declare<T: DevType + ?Sized, K: Kind>( &mut self, d: &FieldDescription<'_, T, K>, ) -> Result<DevField<T, K>, Error>

Declares a developer field, writing its field_description; the handle then gives it values.

use fit_encoder::*;

let app = w.developer(&Developer::new([7; 16])).unwrap();
let smo2: RecordField<u8> = w.declare(&app.field(0, "SmO2").units("%")).unwrap();
let note: SessionField<str> = w.declare(&app.string(1, "Note", 31)).unwrap();
§Errors

Error::OutOfOrder outside the activity; Error::Undeclared for a developer this file did not declare; Error::Duplicate for a number the developer used already; Error::TooMany past DEVELOPER_FIELDS_MAX fields, or past SUMMARY_BYTES_MAX for lap and session fields; Error::OutOfRange for an empty name, a scale of 0, or a string of no length; Error::StringTooLong for a name or units too long.

Source

pub fn developer_value<T: DevType + ?Sized, K: Summary>( &mut self, field: &DevField<T, K>, value: T::Value<'_>, ) -> Result<(), Error>

Gives the open lap or session the value of one of its developer fields, written when it ends. A field given again keeps the last value; one not given is left out.

§Errors

Error::OutOfOrder outside a session; Error::Undeclared for a field this file did not declare; Error::OutOfRange or Error::StringTooLong for a value its field cannot hold.

Source

pub fn raw_message( &mut self, global: u16, fields: &[RawField<'_>], ) -> Result<(), Error>

Writes a message the crate does not model, global message global with fields, as its layout: the explicit way to add what the encoder does not write.

It may not be one the encoder writes itself or derives from what it writes: file_id, device_info, sport, record, length, set, hrv, lap, session, activity, developer_data_id, field_description, or an event for the timer, a session, a lap or the activity, or one with no event. Extra record fields go with Writer::record_with. A timestamp (253) must be a uint32 no earlier than the last time written, and moves the activity on to it.

use fit_encoder::*;

// An event (21): rear_gear_change (43), a marker (3), rear gear 7 with 28 teeth.
let t = RawField::number(253, start.checked_add(5).unwrap().fit());
w.raw_message(21, &[t, RawField::enumeration(0, 43), RawField::enumeration(1, 3),
    RawField::number(11, 7u8), RawField::number(12, 28u8)]).unwrap();
§Errors

Error::Reserved for a message the encoder writes; Error::OutOfOrder outside the activity; Error::TimeWentBack for a time before one already written; Error::Duplicate for a field given twice; Error::TooMany past RAW_FIELDS_MAX fields; Error::OutOfRange or Error::StringTooLong for a value its field cannot hold.

Trait Implementations§

Source§

impl Debug for Writer<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Writer<'a>

§

impl<'a> !Send for Writer<'a>

§

impl<'a> !Sync for Writer<'a>

§

impl<'a> !UnwindSafe for Writer<'a>

§

impl<'a> Forget for Writer<'a>

§

impl<'a> Freeze for Writer<'a>
where &'a mut dyn Out: Freeze, &'a mut State: Freeze,

§

impl<'a> Move for Writer<'a>

§

impl<'a> Unpin for Writer<'a>
where &'a mut dyn Out: Unpin, &'a mut State: Unpin,

§

impl<'a> UnsafeUnpin for Writer<'a>
where &'a mut dyn Out: UnsafeUnpin, &'a mut State: UnsafeUnpin,

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.