Restructure to library / binary combo

This commit is contained in:
2018-05-22 01:07:49 +02:00
parent 236d6839be
commit 2a37620224
11 changed files with 33 additions and 35 deletions

28
src/pool.rs Normal file
View File

@@ -0,0 +1,28 @@
use Result;
use block::Block;
use binread::{BinRead, BinReadable};
#[derive(Debug)]
pub struct Pool {
pub data: Vec<i32>
}
impl Pool {
pub fn new(mut block: Block) -> Result<Pool> {
let cap = block.len() / 4;
let mut vec = Vec::with_capacity(cap);
while block.has_i32() {
vec.push(block.read_i32()?);
}
Ok(Pool {
data: vec
})
}
pub fn get(&self, index: usize) -> Result<i32> {
if index >= self.data.len() {
return Err("No such constant")
}
Ok(self.data[index])
}
}