[array (rust)] Implement array basis

This commit is contained in:
Ming-Hung Tsai
2020-12-09 18:40:06 +08:00
parent 9733ceb949
commit 087a4711a5
4 changed files with 220 additions and 0 deletions

39
src/pdata/array.rs Normal file
View File

@@ -0,0 +1,39 @@
use nom::{number::complete::*, IResult};
use std::fmt;
use crate::pdata::unpack::*;
//------------------------------------------
// TODO: build a data structure representating an array?
// FIXME: rename this struct
pub struct ArrayBlockEntry {
pub block: u64,
}
impl Unpack for ArrayBlockEntry {
fn disk_size() -> u32 {
8
}
fn unpack(i: &[u8]) -> IResult<&[u8], ArrayBlockEntry> {
let (i, n) = le_u64(i)?;
let block = n;
Ok((
i,
ArrayBlockEntry {
block,
}
))
}
}
impl fmt::Display for ArrayBlockEntry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.block)
}
}
//------------------------------------------