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<'_>
impl Writer<'_>
Sourcepub fn start(&mut self, t: Timestamp, creator: &Device<'_>) -> Result<(), Error>
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.
Sourcepub fn device(&mut self, device: &Device<'_>) -> Result<(), Error>
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.
Sourcepub fn session(
&mut self,
t: Timestamp,
sport: Sport,
sub_sport: SubSport,
) -> Result<(), Error>
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.
Sourcepub fn pool_swim(&mut self, t: Timestamp, pool: Pool) -> Result<(), Error>
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.
Sourcepub fn leg(&mut self, t: Timestamp, leg: &Leg<'_>) -> Result<(), Error>
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.
Sourcepub fn record(&mut self, record: &Record) -> Result<(), Error>
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.
Sourcepub fn record_with(
&mut self,
record: &Record,
extras: &[Extra<'_>],
) -> Result<(), Error>
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.
Sourcepub fn lap(&mut self, t: Timestamp) -> Result<(), Error>
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.
Sourcepub fn lap_by(&mut self, t: Timestamp, trigger: LapTrigger) -> Result<(), Error>
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.
Sourcepub fn pause(&mut self, t: Timestamp) -> Result<(), Error>
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.
Sourcepub fn resume(&mut self, t: Timestamp) -> Result<(), Error>
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.
Sourcepub fn length(&mut self, t: Timestamp, length: &Length) -> Result<(), Error>
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.
Sourcepub fn set(&mut self, t: Timestamp, set: &Set) -> Result<(), Error>
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.
Sourcepub fn rest(&mut self, t: Timestamp) -> Result<(), Error>
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.
Sourcepub fn end_rest(&mut self, t: Timestamp) -> Result<(), Error>
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.
Sourcepub fn beat_intervals_ms(&mut self, intervals: &[u16]) -> Result<(), Error>
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.
Sourcepub fn beat_intervals_1024ths(&mut self, intervals: &[u16]) -> Result<(), Error>
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§impl Writer<'_>
impl Writer<'_>
Sourcepub fn developer(&mut self, developer: &Developer) -> Result<Dev, Error>
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.
Sourcepub fn declare<T: DevType + ?Sized, K: Kind>(
&mut self,
d: &FieldDescription<'_, T, K>,
) -> Result<DevField<T, K>, Error>
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.
Sourcepub fn developer_value<T: DevType + ?Sized, K: Summary>(
&mut self,
field: &DevField<T, K>,
value: T::Value<'_>,
) -> Result<(), Error>
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.
Sourcepub fn raw_message(
&mut self,
global: u16,
fields: &[RawField<'_>],
) -> Result<(), Error>
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.