summaryrefslogtreecommitdiff
path: root/src/chunk.rs
blob: f3a7b798d1023e773f5736d52c01b161563b4265 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use serde::Serialize;

/// Store an arbitrary chunk of data.
///
/// The data is just arbitrary binary data.
///
/// A chunk also contains its associated metadata, except its
/// identifier.
#[derive(Debug, Serialize)]
pub struct Chunk {
    data: Vec<u8>,
}

impl Chunk {
    /// Construct a new chunk.
    pub fn new(data: Vec<u8>) -> Self {
        Chunk { data }
    }

    /// Return a chunk's data.
    pub fn data(&self) -> &[u8] {
        &self.data
    }
}