summaryrefslogtreecommitdiff
path: root/src/store.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-12-23 19:35:23 +0200
committerLars Wirzenius <liw@liw.fi>2020-12-23 19:35:23 +0200
commit345c5d822776ef78e594c2365d8bfd39202952e0 (patch)
tree37fbdb673eb03c63c8a909540a885d82d0225357 /src/store.rs
parent4128b937a6bd1ea3944a6a7f00930d40f27f2d2a (diff)
downloadobnam2-345c5d822776ef78e594c2365d8bfd39202952e0.tar.gz
refactor: use a struct instead of a tuple
It seems this is more idiomatic in Rust.
Diffstat (limited to 'src/store.rs')
-rw-r--r--src/store.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/store.rs b/src/store.rs
index a415d7a..123b9fa 100644
--- a/src/store.rs
+++ b/src/store.rs
@@ -61,11 +61,12 @@ impl Store {
}
/// Load a chunk from a store.
- pub fn load(&self, id: &ChunkId) -> anyhow::Result<(ChunkMeta, DataChunk)> {
+ pub fn load(&self, id: &ChunkId) -> anyhow::Result<LoadedChunk> {
let (_, _, dataname) = &self.filenames(id);
let meta = self.load_meta(id)?;
let data = std::fs::read(&dataname)?;
- Ok((meta, DataChunk::new(data)))
+ let data = DataChunk::new(data);
+ Ok(LoadedChunk { meta, data })
}
/// Delete a chunk from a store.
@@ -76,3 +77,22 @@ impl Store {
Ok(())
}
}
+
+pub struct LoadedChunk {
+ meta: ChunkMeta,
+ data: DataChunk,
+}
+
+impl LoadedChunk {
+ pub fn new(meta: ChunkMeta, data: DataChunk) -> Self {
+ Self { meta, data }
+ }
+
+ pub fn meta(&self) -> &ChunkMeta {
+ &self.meta
+ }
+
+ pub fn data(&self) -> &DataChunk {
+ &self.data
+ }
+}