Created
May 12, 2017 22:48
-
-
Save alexmullins/dbdd7bfe1407baf94bb038979f8eaf16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{Read, Write, Seek}; | |
// Driver is the basis for reading and writing words | |
// for use in the filesystem. | |
trait Driver { | |
fn erase_sector(&self, n: u32) -> Result<(), &'static str>; | |
fn erase_all_sectors(&self) -> Result<(), &'static str>; | |
fn read_word(&self, addr: u32) -> Result<u16, &'static str>; | |
fn write_word(&self, addr: u32, val: u16) -> Result<(), &'static str>; | |
} | |
struct ReadWriteSeekDriver<A: Read + Write + Seek> { | |
driver: A, | |
num_sec: u32 | |
} | |
impl<A> ReadWriteSeekDriver<A> | |
where A: Read + Write + Seek { | |
fn new(num_sec: u32, driver: A) -> Self { | |
ReadWriteSeekDriver { | |
num_sec: num_sec, | |
driver: driver | |
} | |
} | |
} | |
impl<A> Driver for ReadWriteSeekDriver<A> | |
where A: Read + Write + Seek { | |
fn erase_sector(&self, n: u32) -> Result<(), &'static str> { unimplemented!() } | |
fn erase_all_sectors(&self) -> Result<(), &'static str> { unimplemented!() } | |
fn read_word(&self, addr: u32) -> Result<u16, &'static str> { unimplemented!() } | |
fn write_word(&self, addr: u32, val: u16) -> Result<(), &'static str> { unimplemented!() } | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
use std::io::Cursor; | |
#[test] | |
fn test_read_write_seek_driver_new() { | |
let a = ReadWriteSeekDriver::new(20, Cursor::new(vec![1,2,3])); | |
a.erase_all_sectors(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment