use crate::{BinaryReader, ConstExpr, FromReader, GlobalType, Result, SectionLimited};
#[derive(Debug, Copy, Clone)]
pub struct Global<'a> {
pub ty: GlobalType,
pub init_expr: ConstExpr<'a>,
}
pub type GlobalSectionReader<'a> = SectionLimited<'a, Global<'a>>;
impl<'a> FromReader<'a> for Global<'a> {
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
let ty = reader.read()?;
let init_expr = reader.read()?;
Ok(Global { ty, init_expr })
}
}
impl<'a> FromReader<'a> for GlobalType {
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
Ok(GlobalType {
content_type: reader.read()?,
mutable: match reader.read_u8()? {
0x00 => false,
0x01 => true,
_ => bail!(reader.original_position() - 1, "malformed mutability",),
},
})
}
}