Restructure to library / binary combo
This commit is contained in:
28
src/pool.rs
Normal file
28
src/pool.rs
Normal 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])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user