Struct linera_witty::MockInstance
source · pub struct MockInstance<UserData> { /* private fields */ }
Expand description
A fake Wasm instance.
Only contains exports for the memory and the canonical ABI allocation functions.
Implementations§
source§impl<UserData> MockInstance<UserData>
impl<UserData> MockInstance<UserData>
sourcepub fn new(user_data: UserData) -> Self
pub fn new(user_data: UserData) -> Self
Creates a new MockInstance
using the provided user_data
.
sourcepub fn with_exported_function<Parameters, Results, Handler>(
self,
name: impl Into<String>,
handler: Handler,
) -> Selfwhere
Parameters: 'static,
Results: 'static,
Handler: Fn(MockInstance<UserData>, Parameters) -> Result<Results, RuntimeError> + 'static,
pub fn with_exported_function<Parameters, Results, Handler>(
self,
name: impl Into<String>,
handler: Handler,
) -> Selfwhere
Parameters: 'static,
Results: 'static,
Handler: Fn(MockInstance<UserData>, Parameters) -> Result<Results, RuntimeError> + 'static,
Adds a mock exported function to this MockInstance
.
The handler
will be called whenever the exported function is called.
sourcepub fn add_exported_function<Parameters, Results, Handler>(
&mut self,
name: impl Into<String>,
handler: Handler,
) -> &mut Selfwhere
Parameters: 'static,
Results: 'static,
Handler: Fn(MockInstance<UserData>, Parameters) -> Result<Results, RuntimeError> + 'static,
pub fn add_exported_function<Parameters, Results, Handler>(
&mut self,
name: impl Into<String>,
handler: Handler,
) -> &mut Selfwhere
Parameters: 'static,
Results: 'static,
Handler: Fn(MockInstance<UserData>, Parameters) -> Result<Results, RuntimeError> + 'static,
Adds a mock exported function to this MockInstance
.
The handler
will be called whenever the exported function is called.
sourcepub fn call_imported_function<Parameters, Results>(
&self,
function: &str,
parameters: Parameters,
) -> Result<Results, RuntimeError>
pub fn call_imported_function<Parameters, Results>( &self, function: &str, parameters: Parameters, ) -> Result<Results, RuntimeError>
Calls a function that the mock instance imported from the host.
sourcepub fn memory_contents(&self) -> Vec<u8> ⓘ
pub fn memory_contents(&self) -> Vec<u8> ⓘ
Returns a copy of the current memory contents.
Trait Implementations§
source§impl<UserData> Clone for MockInstance<UserData>
impl<UserData> Clone for MockInstance<UserData>
source§impl<UserData> Default for MockInstance<UserData>where
UserData: Default,
impl<UserData> Default for MockInstance<UserData>where
UserData: Default,
source§impl<Handler, Parameters, Results, UserData> ExportFunction<Handler, Parameters, Results> for MockInstance<UserData>where
Handler: Fn(MockInstance<UserData>, Parameters) -> Result<Results, RuntimeError> + 'static,
Parameters: 'static,
Results: 'static,
impl<Handler, Parameters, Results, UserData> ExportFunction<Handler, Parameters, Results> for MockInstance<UserData>where
Handler: Fn(MockInstance<UserData>, Parameters) -> Result<Results, RuntimeError> + 'static,
Parameters: 'static,
Results: 'static,
source§impl<UserData> Instance for MockInstance<UserData>
impl<UserData> Instance for MockInstance<UserData>
§type Runtime = MockRuntime
type Runtime = MockRuntime
The runtime this instance is running in.
§type UserDataReference<'a> = MutexGuard<'a, UserData>
where
Self::UserData: 'a,
Self: 'a
type UserDataReference<'a> = MutexGuard<'a, UserData> where Self::UserData: 'a, Self: 'a
A reference to the custom user data stored in the instance.
§type UserDataMutReference<'a> = MutexGuard<'a, UserData>
where
Self::UserData: 'a,
Self: 'a
type UserDataMutReference<'a> = MutexGuard<'a, UserData> where Self::UserData: 'a, Self: 'a
A mutable reference to the custom user data stored in the instance.
source§fn load_export(&mut self, name: &str) -> Option<String>
fn load_export(&mut self, name: &str) -> Option<String>
Loads an export from the guest module.
source§fn user_data(&self) -> Self::UserDataReference<'_>
fn user_data(&self) -> Self::UserDataReference<'_>
Returns a reference to the custom user data stored in this instance.
source§fn user_data_mut(&mut self) -> Self::UserDataMutReference<'_>
fn user_data_mut(&mut self) -> Self::UserDataMutReference<'_>
Returns a mutable reference to the custom user data stored in this instance.
source§impl<Parameters, Results, UserData> InstanceWithFunction<Parameters, Results> for MockInstance<UserData>where
Parameters: FlatLayout + 'static,
Results: FlatLayout + 'static,
impl<Parameters, Results, UserData> InstanceWithFunction<Parameters, Results> for MockInstance<UserData>where
Parameters: FlatLayout + 'static,
Results: FlatLayout + 'static,
source§fn function_from_export(
&mut self,
name: <Self::Runtime as Runtime>::Export,
) -> Result<Option<Self::Function>, RuntimeError>
fn function_from_export( &mut self, name: <Self::Runtime as Runtime>::Export, ) -> Result<Option<Self::Function>, RuntimeError>
Converts an export into a function, if it is one.
source§fn call(
&mut self,
function: &Self::Function,
parameters: Parameters,
) -> Result<Results, RuntimeError>
fn call( &mut self, function: &Self::Function, parameters: Parameters, ) -> Result<Results, RuntimeError>
Calls the
function
from this instance using the specified parameters
.source§fn load_function(&mut self, name: &str) -> Result<Self::Function, RuntimeError>
fn load_function(&mut self, name: &str) -> Result<Self::Function, RuntimeError>
Loads a function from the guest Wasm instance.
source§impl<UserData> InstanceWithMemory for MockInstance<UserData>
impl<UserData> InstanceWithMemory for MockInstance<UserData>
source§impl<UserData> RuntimeMemory<MockInstance<UserData>> for Arc<Mutex<Vec<u8>>>
impl<UserData> RuntimeMemory<MockInstance<UserData>> for Arc<Mutex<Vec<u8>>>
source§fn read<'instance>(
&self,
instance: &'instance MockInstance<UserData>,
location: GuestPointer,
length: u32,
) -> Result<Cow<'instance, [u8]>, RuntimeError>
fn read<'instance>( &self, instance: &'instance MockInstance<UserData>, location: GuestPointer, length: u32, ) -> Result<Cow<'instance, [u8]>, RuntimeError>
Reads
length
bytes from memory from the provided location
.source§fn write(
&mut self,
instance: &mut MockInstance<UserData>,
location: GuestPointer,
bytes: &[u8],
) -> Result<(), RuntimeError>
fn write( &mut self, instance: &mut MockInstance<UserData>, location: GuestPointer, bytes: &[u8], ) -> Result<(), RuntimeError>
Writes the
bytes
to memory at the provided location
.Auto Trait Implementations§
impl<UserData> Freeze for MockInstance<UserData>
impl<UserData> !RefUnwindSafe for MockInstance<UserData>
impl<UserData> !Send for MockInstance<UserData>
impl<UserData> !Sync for MockInstance<UserData>
impl<UserData> Unpin for MockInstance<UserData>
impl<UserData> !UnwindSafe for MockInstance<UserData>
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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
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)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.
source§impl<T> MockResults for T
impl<T> MockResults for T
§type Results = T
type Results = T
The mock native type of the results for the
MockInstance
.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
source§fn read<'instance>(
&self,
instance: &'instance &mut I,
location: GuestPointer,
length: u32,
) -> Result<Cow<'instance, [u8]>, RuntimeError>
fn read<'instance>( &self, instance: &'instance &mut I, location: GuestPointer, length: u32, ) -> Result<Cow<'instance, [u8]>, RuntimeError>
Reads length
bytes from memory from the provided location
.
source§fn write(
&mut self,
instance: &mut &mut I,
location: GuestPointer,
bytes: &[u8],
) -> Result<(), RuntimeError>
fn write( &mut self, instance: &mut &mut I, location: GuestPointer, bytes: &[u8], ) -> Result<(), RuntimeError>
Writes the bytes
to memory at the provided location
.