creek_core/write/
data.rs

1/// A block to write data to.
2pub struct WriteBlock<T: Copy + Clone + Default + Send> {
3    pub(crate) block: Vec<Vec<T>>,
4
5    pub(crate) restart_count: usize,
6}
7
8impl<T: Copy + Clone + Default + Send> WriteBlock<T> {
9    pub fn new(num_channels: usize, block_size: usize) -> Self {
10        WriteBlock {
11            block: (0..num_channels)
12                .map(|_| Vec::with_capacity(block_size))
13                .collect(),
14            restart_count: 0,
15        }
16    }
17
18    pub fn block(&self) -> &[Vec<T>] {
19        self.block.as_slice()
20    }
21
22    pub fn written_frames(&self) -> usize {
23        self.block[0].len()
24    }
25
26    pub fn clear(&mut self) {
27        for ch in self.block.iter_mut() {
28            ch.clear();
29        }
30    }
31}
32
33pub(crate) struct HeapData<T: Copy + Clone + Default + Send> {
34    pub block_pool: Vec<WriteBlock<T>>,
35    pub current_block: Option<WriteBlock<T>>,
36    pub next_block: Option<WriteBlock<T>>,
37}