Skip to content

Commit

Permalink
[storage] Add FileIndex #59 (#60)
Browse files Browse the repository at this point in the history
* Create file_index.rs

* Update storage.rs

* Update file_index.rs

* Update file_storage.rs
  • Loading branch information
michaelvlach authored Aug 21, 2022
1 parent bd7fa43 commit 7357a9a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/storage.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mod file_index;
mod file_storage;
12 changes: 12 additions & 0 deletions src/storage/file_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[derive(Default)]
pub(crate) struct FileIndex {}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn file_index_can_be_default_constructed() {
let _index = FileIndex::default();
}
}
17 changes: 11 additions & 6 deletions src/storage/file_storage.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use super::file_index::FileIndex;
use std::fs::{File, OpenOptions};

#[allow(dead_code)]
pub(crate) struct FileStorage {
filename: String,
file: File,
index: FileIndex,
}

impl From<&str> for FileStorage {
Expand All @@ -14,14 +16,17 @@ impl From<&str> for FileStorage {

impl From<String> for FileStorage {
fn from(filename: String) -> Self {
let file = OpenOptions::new()
.write(true)
.create(true)
.read(true)
.open(&filename)
.unwrap();

FileStorage {
file: OpenOptions::new()
.write(true)
.create(true)
.read(true)
.open(&filename)
.unwrap(),
filename,
file,
index: FileIndex::default(),
}
}
}
Expand Down

0 comments on commit 7357a9a

Please sign in to comment.