hff_core/write/
table_array.rs1use crate::{ByteOrder, Result, Table};
2use std::ops::{Index, IndexMut};
3
4#[derive(Debug)]
6pub struct TableArray {
7 tables: Vec<(bool, Table)>,
10}
11
12impl TableArray {
13 pub fn new() -> Self {
15 Self { tables: vec![] }
16 }
17
18 pub fn len(&self) -> usize {
20 self.tables.len()
21 }
22
23 pub fn push(&mut self, has_metadata: bool, table: Table) {
25 self.tables.push((has_metadata, table));
26 }
27
28 pub fn last_mut(&mut self) -> Option<&mut (bool, Table)> {
30 self.tables.last_mut()
31 }
32
33 pub fn to_bytes<E: ByteOrder>(self) -> Result<Vec<u8>> {
36 let mut buffer = vec![];
37 for table in self.tables {
38 table.1.write::<E>(&mut buffer)?;
39 }
40 Ok(buffer)
41 }
42}
43
44impl Index<usize> for TableArray {
45 type Output = (bool, Table);
46
47 fn index(&self, index: usize) -> &Self::Output {
48 &self.tables[index]
49 }
50}
51
52impl IndexMut<usize> for TableArray {
53 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
54 &mut self.tables[index]
55 }
56}