1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* seek.rs
 *
 * Developed by Tim Walls <tim.walls@snowgoons.com>
 * Copyright (c) All Rights Reserved, Tim Walls
 */
//! Trait for seekable storage devices
//!
//!

// Imports ===================================================================
use avrox_storage::{FileAddr, FileOffset};
use avr_oxide::OxideResult::Ok;

// Declarations ==============================================================
/// Possible methods to seek within an I/O object
#[derive(Copy,Clone,Eq,PartialEq)]
pub enum SeekFrom {
  /// Given number of bytes from start
  Start(FileAddr),
  /// Given number of bytes from the end
  End(FileOffset),
  /// Given number of bytes from the current position
  Current(FileOffset)
}


pub trait Seek {
  fn seek(&mut self, pos: SeekFrom) -> avr_oxide::io::Result<FileAddr>;
  fn rewind(&mut self) -> avr_oxide::io::Result<()> {
    self.seek(SeekFrom::Start(FileAddr::MIN))?;
    Ok(())
  }
  fn stream_position(&mut self) -> avr_oxide::io::Result<FileAddr>;
}

// Code ======================================================================

// Tests =====================================================================