[−][src]Crate gwasm_api
gwasm-api - gWasm API for Rust apps
gWasm is Golem's new meta use-case which allows Golem's developers/users to deploy their Wasm apps on Golem Network. This API providers convenience structures and functions for creating a gWasm task and connecting with Golem Network all from native Rust code.
Example
use gwasm_api::prelude::*; use anyhow::Result; use std::path::PathBuf; struct ProgressTracker; impl ProgressUpdate for ProgressTracker { fn update(&self, progress: f64) { println!("Current progress = {}", progress); } } fn main() -> Result<()> { let binary = GWasmBinary { js: &[0u8; 100], // JavaScript file generated by Emscripten wasm: &[0u8; 100], // Wasm binary generated by Emscripten }; let task = TaskBuilder::try_new("workspace", binary)? .push_subtask_data(vec![0u8; 100]) .build()?; let computed_task = compute( PathBuf::from("datadir"), "127.0.0.1".to_string(), 61000, Net::TestNet, task, ProgressTracker, )?; for subtask in computed_task.subtasks { for (_, reader) in subtask.data { assert!(!reader.buffer().is_empty()); } } Ok(()) }
Subtask input/output
For each subtask, two command line arguments are passed to the WASM binary. Conceptually, you should expect your application to be invoked as:
./app input output
where:
input
is the input file pathoutput
is the expected output file path
The app is expected to create the output
file or the task will fail.
Applications requiring multiple input or output files are currently unsupported.
For more information about how to write gWASM apps see the sp-wasm documentation
More examples
- g-flite is a CLI which uses
gwasm-api
internally
Modules
error | Errors that can be returned by the library |
golem | Convenience async functions for creating gWasm tasks, connecting to a Golem instance, and listening for task's progress as it's computed on Golem. |
prelude | The |
task | Convenience types for creating and managing gWasm tasks |
timeout | Types representing Golem Task's timeout values |
Enums
Net |
Traits
ProgressUpdate | Trait specifying the required interface for an object tracking the computation's progress |
Functions
compute | A convenience function for running a gWasm |