pub struct Plugin {
pub id: Uuid,
/* private fields */
}
Expand description
Plugin contains everything needed to execute a WASM function
Fields§
§id: Uuid
A unique ID for each plugin
Implementations§
source§impl Plugin
impl Plugin
sourcepub fn new<'a>(
wasm: impl Into<WasmInput<'a>>,
imports: impl IntoIterator<Item = Function>,
with_wasi: bool
) -> Result<Plugin, Error>
pub fn new<'a>( wasm: impl Into<WasmInput<'a>>, imports: impl IntoIterator<Item = Function>, with_wasi: bool ) -> Result<Plugin, Error>
Create a new plugin from a Manifest or WebAssembly module, and host functions. The with_wasi
parameter determines whether or not the module should be executed with WASI enabled.
sourcepub fn function_exists(&mut self, function: impl AsRef<str>) -> bool
pub fn function_exists(&mut self, function: impl AsRef<str>) -> bool
Returns true
if the given function exists, otherwise false
sourcepub fn reset(&mut self) -> Result<(), Error>
pub fn reset(&mut self) -> Result<(), Error>
Reset Extism runtime, this will invalidate all allocated memory
sourcepub fn call<'a, 'b, T: ToBytes<'a>, U: FromBytes<'b>>(
&'b mut self,
name: impl AsRef<str>,
input: T
) -> Result<U, Error>
pub fn call<'a, 'b, T: ToBytes<'a>, U: FromBytes<'b>>( &'b mut self, name: impl AsRef<str>, input: T ) -> Result<U, Error>
Call a function by name with the given input, the return value is the output data returned by the plugin. The return type can be anything that implements FromBytes. This data will be invalidated next time the plugin is called.
§Arguments
name
- A string representing the name of the export function to callinput
- The input argument to the function. Type should implment ToBytes.
§Examples
// call takes a ToBytes and FromBytes type
// this function takes an &str and returns an &str
let output = plugin.call::<&str, &str>("greet", "Benjamin")?;
assert_eq!(output, "Hello, Benjamin!");
sourcepub fn call_get_error_code<'a, 'b, T: ToBytes<'a>, U: FromBytes<'b>>(
&'b mut self,
name: impl AsRef<str>,
input: T
) -> Result<U, (Error, i32)>
pub fn call_get_error_code<'a, 'b, T: ToBytes<'a>, U: FromBytes<'b>>( &'b mut self, name: impl AsRef<str>, input: T ) -> Result<U, (Error, i32)>
Similar to Plugin::call
, but returns the Extism error code along with the
Error
. It is assumed if Ok(_)
is returned that the error code was 0
.
All Extism plugin calls return an error code, Plugin::call
consumes the error code,
while Plugin::call_get_error_code
preserves it - this function should only be used
when you need to inspect the actual return value of a plugin function when it fails.
sourcepub fn cancel_handle(&self) -> CancelHandle
pub fn cancel_handle(&self) -> CancelHandle
Get a CancelHandle
, which can be used from another thread to cancel a running plugin
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Plugin
impl !RefUnwindSafe for Plugin
impl Unpin for Plugin
impl !UnwindSafe for Plugin
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> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self
file descriptor.source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self
file descriptor. Read more