[−][src]Struct wasmer::Global
A WebAssembly global
instance.
A global instance is the runtime representation of a global variable. It consists of an individual value and a flag indicating whether it is mutable.
Spec: https://webassembly.github.io/spec/core/exec/runtime.html#global-instances
Implementations
impl Global
[src]
pub fn new(store: &Store, val: Val) -> Self
[src]
Create a new Global
with the initial value Val
.
Example
let g = Global::new(&store, Value::I32(1)); assert_eq!(g.get(), Value::I32(1)); assert_eq!(g.ty().mutability, Mutability::Const);
pub fn new_mut(store: &Store, val: Val) -> Self
[src]
Create a mutable Global
with the initial value Val
.
Example
let g = Global::new_mut(&store, Value::I32(1)); assert_eq!(g.get(), Value::I32(1)); assert_eq!(g.ty().mutability, Mutability::Var);
pub fn ty(&self) -> &GlobalType
[src]
Returns the GlobalType
of the Global
.
Example
let c = Global::new(&store, Value::I32(1)); let v = Global::new_mut(&store, Value::I64(1)); assert_eq!(c.ty(), &GlobalType::new(Type::I32, Mutability::Const)); assert_eq!(v.ty(), &GlobalType::new(Type::I64, Mutability::Var));
pub fn store(&self) -> &Store
[src]
Returns the Store
where the Global
belongs.
Example
let g = Global::new(&store, Value::I32(1)); assert_eq!(g.store(), &store);
pub fn get(&self) -> Val
[src]
Retrieves the current value Val
that the Global has.
Example
let g = Global::new(&store, Value::I32(1)); assert_eq!(g.get(), Value::I32(1));
pub fn set(&self, val: Val) -> Result<(), RuntimeError>
[src]
Sets a custom value Val
to the runtime Global.
Example
let g = Global::new_mut(&store, Value::I32(1)); assert_eq!(g.get(), Value::I32(1)); g.set(Value::I32(2)); assert_eq!(g.get(), Value::I32(2));
Errors
Trying to mutate a immutable global will raise an error:
let g = Global::new(&store, Value::I32(1)); g.set(Value::I32(2)).unwrap();
Trying to set a value of a incompatible type will raise an error:
let g = Global::new(&store, Value::I32(1)); // This results in an error: `RuntimeError`. g.set(Value::I64(2)).unwrap();
pub fn same(&self, other: &Self) -> bool
[src]
Returns whether or not these two globals refer to the same data.
Example
let g = Global::new(&store, Value::I32(1)); assert!(g.same(&g));
Trait Implementations
impl Clone for Global
[src]
impl Debug for Global
[src]
impl<'a> Exportable<'a> for Global
[src]
pub fn to_export(&self) -> Export
[src]
pub fn get_self_from_extern(
_extern: &'a Extern
) -> Result<&'a Self, ExportError>
[src]
_extern: &'a Extern
) -> Result<&'a Self, ExportError>
impl From<Global> for Extern
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Global
[src]
impl Send for Global
[src]
impl Sync for Global
[src]
impl Unpin for Global
[src]
impl !UnwindSafe for Global
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,