pub struct Instance<T>(/* private fields */);
Implementations§
source§impl<T> Instance<T>
impl<T> Instance<T>
sourcepub fn call(
&self,
state_args: StateArgs,
call_args: CallArgs<'_, T>,
) -> Result<(), ExecutionError<Error>>
pub fn call( &self, state_args: StateArgs, call_args: CallArgs<'_, T>, ) -> Result<(), ExecutionError<Error>>
Updates the state of the instance according to the state_args
and calls a given function.
sourcepub fn call_typed<FnArgs, FnResult>(
&self,
user_data: &mut T,
symbol: impl AsRef<[u8]>,
args: FnArgs,
) -> Result<FnResult, ExecutionError<Error>>where
FnArgs: FuncArgs,
FnResult: FuncResult,
pub fn call_typed<FnArgs, FnResult>(
&self,
user_data: &mut T,
symbol: impl AsRef<[u8]>,
args: FnArgs,
) -> Result<FnResult, ExecutionError<Error>>where
FnArgs: FuncArgs,
FnResult: FuncResult,
A conveniance function to call into this particular instance according to the default ABI.
This is equivalent to calling Instance::call
with an appropriately set up CallArgs
.
sourcepub fn update_state(
&self,
state_args: StateArgs,
) -> Result<(), ExecutionError<Error>>
pub fn update_state( &self, state_args: StateArgs, ) -> Result<(), ExecutionError<Error>>
Updates the state of this particular instance.
sourcepub fn reset_memory(&self) -> Result<(), Error>
pub fn reset_memory(&self) -> Result<(), Error>
A conveniance function to reset the instance’s memory to its initial state from when it was first instantiated.
This is equivalent to calling Instance::update_state
with an appropriately set up StateArgs
.
sourcepub fn sbrk(&self, size: u32) -> Result<Option<u32>, Error>
pub fn sbrk(&self, size: u32) -> Result<Option<u32>, Error>
A conveniance function to increase the size of the program’s heap by a given number of bytes, allocating memory if necessary.
If successful returns a pointer to the end of the guest’s heap.
This is equivalent to manually checking that the size
bytes can actually be allocated, calling Instance::sbrk
with an appropriately set up StateArgs
,
and calculating the new address of the end of the guest’s heap.
pub fn read_memory_into_slice<'slice, B>(
&self,
address: u32,
buffer: &'slice mut B,
) -> Result<&'slice mut [u8], Trap>where
B: ?Sized + AsUninitSliceMut,
pub fn read_memory_into_vec( &self, address: u32, length: u32, ) -> Result<Vec<u8>, Trap>
pub fn write_memory(&self, address: u32, data: &[u8]) -> Result<(), Trap>
sourcepub fn get_result_typed<FnResult>(&self) -> FnResultwhere
FnResult: FuncResult,
pub fn get_result_typed<FnResult>(&self) -> FnResultwhere
FnResult: FuncResult,
Extracts a return value from the argument registers according to the default ABI.
This is equivalent to manually calling Instance::get_reg
.
sourcepub fn gas_remaining(&self) -> Option<Gas>
pub fn gas_remaining(&self) -> Option<Gas>
Gets the amount of gas remaining, or None
if gas metering is not enabled for this instance.
Note that this being zero doesn’t necessarily mean that the execution ran out of gas, if the program ended up consuming exactly the amount of gas that it was provided with!
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Instance<T>
impl<T> !RefUnwindSafe for Instance<T>
impl<T> Send for Instance<T>
impl<T> Sync for Instance<T>
impl<T> Unpin for Instance<T>
impl<T> !UnwindSafe for Instance<T>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)