pub struct SimpleSandbox;
Expand description
One-liner execution functions for maximum ease of use
Implementations§
Source§impl SimpleSandbox
impl SimpleSandbox
Sourcepub async fn run<T, P>(
source_path: P,
function_name: &str,
args: &[Value],
) -> Result<T>
pub async fn run<T, P>( source_path: P, function_name: &str, args: &[Value], ) -> Result<T>
Execute a single function with minimal setup - the simplest possible API
§Examples
use wasm_sandbox::simple;
#[tokio::main]
async fn main() -> Result<(), wasm_sandbox::SandboxError> {
// Execute a function from a Rust source file
let result: i32 = simple::run("./calculator.rs", "add", &[serde_json::Value::from(5), serde_json::Value::from(3)]).await?;
// Execute from pre-compiled WASM
let result: String = simple::run("./module.wasm", "process", &[serde_json::Value::from("hello")]).await?;
Ok(())
}
Sourcepub async fn run_with_config<T, P>(
source_path: P,
function_name: &str,
args: &[Value],
config: InstanceConfig,
) -> Result<T>
pub async fn run_with_config<T, P>( source_path: P, function_name: &str, args: &[Value], config: InstanceConfig, ) -> Result<T>
Execute with custom configuration but still simple
§Examples
use wasm_sandbox::{simple, InstanceConfig, MemoryUnit};
#[tokio::main]
async fn main() -> Result<(), wasm_sandbox::SandboxError> {
let config = InstanceConfig::builder()
.memory_limit(128.mb())
.timeout(60)
.filesystem_read(&["/data"])
.build()?;
let result: Vec<String> = simple::run_with_config(
"./data_processor.rs",
"process_files",
&["/data/input.txt".into()],
config
).await?;
Ok(())
}
Sourcepub async fn run_sequence<P>(
source_path: P,
function_calls: &[(&str, Vec<Value>)],
) -> Result<Vec<Value>>
pub async fn run_sequence<P>( source_path: P, function_calls: &[(&str, Vec<Value>)], ) -> Result<Vec<Value>>
Execute multiple functions in sequence with the same instance
§Examples
use wasm_sandbox::simple;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), wasm_sandbox::SandboxError> {
let calls = vec![
("initialize", vec![json!("config.json")]),
("process", vec![json!("data1.txt")]),
("process", vec![json!("data2.txt")]),
("finalize", vec![]),
];
let results = simple::run_sequence("./processor.rs", &calls).await?;
Ok(())
}
Sourcepub async fn run_sequence_with_config<P>(
source_path: P,
function_calls: Vec<(String, Vec<Value>)>,
config: InstanceConfig,
) -> Result<Vec<Value>>
pub async fn run_sequence_with_config<P>( source_path: P, function_calls: Vec<(String, Vec<Value>)>, config: InstanceConfig, ) -> Result<Vec<Value>>
Execute multiple functions with custom configuration
Sourcepub async fn create_reusable<P>(source_path: P) -> Result<ReusableSandbox>
pub async fn create_reusable<P>(source_path: P) -> Result<ReusableSandbox>
Create a reusable sandbox instance for multiple operations
§Examples
use wasm_sandbox::simple;
#[tokio::main]
async fn main() -> Result<(), wasm_sandbox::SandboxError> {
// Create a reusable sandbox
let mut sandbox = simple::create_reusable("./calculator.rs").await?;
// Use it multiple times
let result1: i32 = sandbox.call("add".to_string(), vec![serde_json::Value::from(5), serde_json::Value::from(3)]).await?;
let result2: i32 = sandbox.call("multiply".to_string(), vec![serde_json::Value::from(4), serde_json::Value::from(6)]).await?;
Ok(())
}
Sourcepub async fn create_reusable_with_config<P>(
source_path: P,
config: InstanceConfig,
) -> Result<ReusableSandbox>
pub async fn create_reusable_with_config<P>( source_path: P, config: InstanceConfig, ) -> Result<ReusableSandbox>
Create a reusable sandbox with custom configuration
Auto Trait Implementations§
impl Freeze for SimpleSandbox
impl RefUnwindSafe for SimpleSandbox
impl Send for SimpleSandbox
impl Sync for SimpleSandbox
impl Unpin for SimpleSandbox
impl UnwindSafe for SimpleSandbox
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
Mutably borrows from an owned value. Read more
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,
Query the “status” flags for the
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,
Set the “status” flags for the
self
file descriptor. Read moreSource§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 more