diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-09-17 09:28:41 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-09-17 09:28:41 +0300 |
commit | 0bc14ecaafabc6be57392e9092f07472c440ae46 (patch) | |
tree | ecff8cb09ae2db6bce772a1ab8664291e535f036 /src/chunk.rs | |
parent | 7155b46602f741694debb4e1764bfa74f3d5c25b (diff) | |
download | obnam2-0bc14ecaafabc6be57392e9092f07472c440ae46.tar.gz |
feat: add initial Chunk struct
Diffstat (limited to 'src/chunk.rs')
-rw-r--r-- | src/chunk.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/chunk.rs b/src/chunk.rs new file mode 100644 index 0000000..29d64a2 --- /dev/null +++ b/src/chunk.rs @@ -0,0 +1,29 @@ +use crate::chunkmeta::ChunkMeta; + +/// Store an arbitrary chunk of data. +/// +/// The data is just arbitrary binary data. +/// +/// A chunk also contains its associated metadata, except its +/// identifier. +pub struct Chunk { + meta: ChunkMeta, + data: Vec<u8>, +} + +impl Chunk { + /// Construct a new chunk. + pub fn new(meta: ChunkMeta, data: Vec<u8>) -> Self { + Chunk { meta, data } + } + + /// Return a chunk's metadata. + pub fn meta(&self) -> &ChunkMeta { + &self.meta + } + + /// Return a chunk's data. + pub fn data(&self) -> &[u8] { + &self.data + } +} |