diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-12-23 19:35:23 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-12-23 19:35:23 +0200 |
commit | 345c5d822776ef78e594c2365d8bfd39202952e0 (patch) | |
tree | 37fbdb673eb03c63c8a909540a885d82d0225357 /src/store.rs | |
parent | 4128b937a6bd1ea3944a6a7f00930d40f27f2d2a (diff) | |
download | obnam2-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.rs | 24 |
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 + } +} |