TestHost

Struct TestHost 

Source
pub struct TestHost<'a, R, BackingStore> {
    pub rng_used: bool,
    pub debug_events: Vec<EmittedDebugStatement>,
    /* private fields */
}
Expand description

A host which traps for any function call apart from report_error which it prints to standard out and get_random that calls a random number generator.

Fields§

§rng_used: bool

A flag set to true if the RNG was used.

§debug_events: Vec<EmittedDebugStatement>

Debug statements in the order they were emitted.

Implementations§

Source§

impl<'a, R: RngCore, BackingStore> TestHost<'a, R, BackingStore>

Source

pub fn new(rng: R, state: InstanceState<'a, BackingStore>) -> Self

Create a new TestHost instance with the given RNG, set the flag to unused, no debug events and use the provided instance state for state-related host function calls.

Trait Implementations§

Source§

impl<'a, R: RngCore, BackingStore: BackingStoreLoad> Host<ArtifactNamedImport> for TestHost<'a, R, BackingStore>

Source§

type Interrupt = NoInterrupt

Source§

fn tick_initial_memory(&mut self, _num_pages: u32) -> RunResult<()>

Charge the given amount of energy for the initial memory. The argument is the number of pages.
Source§

fn call( &mut self, f: &ArtifactNamedImport, memory: &mut [u8], stack: &mut RuntimeStack, ) -> RunResult<Option<NoInterrupt>>

Call the specified host function, giving it access to the current memory and stack. The return value of Ok(None) signifies that execution succeeded and the machine should proceeed, the return value of Ok(Some(i)) indicates that an interrupt was triggered by the host function, and the return value of Err(_) signifies a trap, i.e., the host function was called with illegal arguments. Read more
Source§

fn tick_energy(&mut self, _energy: u64) -> RunResult<()>

Consume a given amount of NRG.
Source§

fn track_call(&mut self) -> RunResult<()>

Track a function call. This is called upon entry to a function. The corresonding track_return is called upon return from a function. These two together can be used to track function call stack depth. track_call can return an Err to indicate that a call stack depth was exceeded. This will lead to immediate termination of execution.
Source§

fn track_return(&mut self)

Called when a function returns. See documentation of track_call for details.

Auto Trait Implementations§

§

impl<'a, R, BackingStore> Freeze for TestHost<'a, R, BackingStore>
where R: Freeze, BackingStore: Freeze,

§

impl<'a, R, BackingStore> RefUnwindSafe for TestHost<'a, R, BackingStore>
where R: RefUnwindSafe, BackingStore: RefUnwindSafe,

§

impl<'a, R, BackingStore> !Send for TestHost<'a, R, BackingStore>

§

impl<'a, R, BackingStore> Sync for TestHost<'a, R, BackingStore>
where R: Sync, BackingStore: Sync,

§

impl<'a, R, BackingStore> Unpin for TestHost<'a, R, BackingStore>
where R: Unpin, BackingStore: Unpin,

§

impl<'a, R, BackingStore> UnwindSafe for TestHost<'a, R, BackingStore>
where R: UnwindSafe, BackingStore: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V