pub struct Global { /* private fields */ }Expand description
Each global stores a single value of the given global type. Its ๐๐๐๐พ also specifies whether a global is immutable or mutable. Moreover, each global is initialized with an ๐๐๐๐ value given by a constant initializer expression. Globals are referenced through global indices, starting with the smallest index not referencing a global import.
See https://webassembly.github.io/spec/core/syntax/modules.html#globals
ยงExamples
ยงImmutable
use wasm_ast::{Global, GlobalType, ValueType, Expression};
let kind = GlobalType::immutable(ValueType::I64);
let initializer: Expression = vec![0i64.into()].into();
let global = Global::immutable(ValueType::I64, initializer.clone());
assert_eq!(global, Global::new(kind.clone(), initializer.clone()));
assert_eq!(global.kind(), &kind);
assert_eq!(global.initializer(), &initializer);ยงMutable
use wasm_ast::{Global, GlobalType, ValueType, Expression};
let kind = GlobalType::mutable(ValueType::I64);
let initializer: Expression = vec![0i64.into()].into();
let global = Global::mutable(ValueType::I64, initializer.clone());
assert_eq!(global, Global::new(kind.clone(), initializer.clone()));
assert_eq!(global.kind(), &kind);
assert_eq!(global.initializer(), &initializer);Implementationsยง
Sourceยงimpl Global
impl Global
Sourcepub fn new(kind: GlobalType, initializer: Expression) -> Self
pub fn new(kind: GlobalType, initializer: Expression) -> Self
Creates a new Global with the given type and initializer.
Sourcepub fn mutable(kind: ValueType, initializer: Expression) -> Self
pub fn mutable(kind: ValueType, initializer: Expression) -> Self
Creates a new Global for a mutable global variable.
Sourcepub fn immutable(kind: ValueType, initializer: Expression) -> Self
pub fn immutable(kind: ValueType, initializer: Expression) -> Self
Creates a new Global for an immutable global variable.
Sourcepub fn kind(&self) -> &GlobalType
pub fn kind(&self) -> &GlobalType
The type of this Global.
Sourcepub fn initializer(&self) -> &Expression
pub fn initializer(&self) -> &Expression
The expression to initialize this Global with.
Trait Implementationsยง
impl StructuralPartialEq for Global
Auto Trait Implementationsยง
impl Freeze for Global
impl RefUnwindSafe for Global
impl Send for Global
impl Sync for Global
impl Unpin for Global
impl UnwindSafe for Global
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more