pub struct OnePass<S: PatchSink> { /* private fields */ }Expand description
Writes a file as its messages arrive, in one pass: the header goes first with no length,
and OnePass::finish patches the length in. For sources that cannot run twice, such as a
live recording or a conversion read once; the bytes are those write() would write.
use fit_encoder::*;
let start = Timestamp::from_unix(1_764_547_200).unwrap();
let mut buf = [0u8; 2048];
let mut file = OnePass::new(SliceSink::new(&mut buf), Options::new()).unwrap();
let mut w = file.writer();
w.start(start, &Device::new(Manufacturer::DEVELOPMENT, 1)).unwrap();
w.session(start, Sport::WALKING, SubSport::GENERIC).unwrap();
for s in 0..10 {
w.record(&Record::new(start.checked_add(s).unwrap()).heart_rate(100)).unwrap();
}
w.end(start.checked_add(10).unwrap()).unwrap();
let sink = file.finish().unwrap();
assert_eq!(&sink.written()[8..12], b".FIT");Implementations§
Source§impl<S: PatchSink> OnePass<S>
impl<S: PatchSink> OnePass<S>
Sourcepub fn finish(self) -> Result<S, FinishError<Self, S::Error>>
pub fn finish(self) -> Result<S, FinishError<Self, S::Error>>
Patches the header’s length in and writes the file CRC. On failure the file comes back with the error, so an activity not yet ended can be ended and finished again; after a sink error, finishing fails again.
§Errors
WriteError::Sink with the sink’s error, including one a message met, or
WriteError::Source with Error::Unfinished if the activity was not ended.
Trait Implementations§
Auto Trait Implementations§
impl<S> Forget for OnePass<S>
impl<S> Freeze for OnePass<S>
impl<S> Move for OnePass<S>
impl<S> RefUnwindSafe for OnePass<S>
impl<S> Send for OnePass<S>
impl<S> Sync for OnePass<S>
impl<S> Unpin for OnePass<S>
impl<S> UnsafeUnpin for OnePass<S>
impl<S> UnwindSafe for OnePass<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more