parity_wasm/elements/
global_entry.rs

1use super::{Deserialize, Error, GlobalType, InitExpr, Serialize};
2use crate::io;
3
4/// Global entry in the module.
5#[derive(Clone, Debug, PartialEq)]
6pub struct GlobalEntry {
7	global_type: GlobalType,
8	init_expr: InitExpr,
9}
10
11impl GlobalEntry {
12	/// New global entry.
13	pub fn new(global_type: GlobalType, init_expr: InitExpr) -> Self {
14		GlobalEntry { global_type, init_expr }
15	}
16	/// Global type.
17	pub fn global_type(&self) -> &GlobalType {
18		&self.global_type
19	}
20	/// Initialization expression (instructions) for global.
21	pub fn init_expr(&self) -> &InitExpr {
22		&self.init_expr
23	}
24	/// Global type (mutable).
25	pub fn global_type_mut(&mut self) -> &mut GlobalType {
26		&mut self.global_type
27	}
28	/// Initialization expression (instructions) for global (mutable).
29	pub fn init_expr_mut(&mut self) -> &mut InitExpr {
30		&mut self.init_expr
31	}
32}
33
34impl Deserialize for GlobalEntry {
35	type Error = Error;
36
37	fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
38		let global_type = GlobalType::deserialize(reader)?;
39		let init_expr = InitExpr::deserialize(reader)?;
40
41		Ok(GlobalEntry { global_type, init_expr })
42	}
43}
44
45impl Serialize for GlobalEntry {
46	type Error = Error;
47
48	fn serialize<W: io::Write>(self, writer: &mut W) -> Result<(), Self::Error> {
49		self.global_type.serialize(writer)?;
50		self.init_expr.serialize(writer)
51	}
52}