This PR adds a wrapper high-level and safe rust API for the generated rust bindings.
The key changes
Change the generated types and functions to private, such as wasi_ephemeral_nn::*.
Add high-level API.
Update the example code and add library documents.
Details
For Convenience
Add Error and BackendError enum for error handling, and introduce a dependency thiserror. (replace NnErrno)
Add GraphEncoding, ExecutionTarget, and TensorType enum to replace the corresponding types in generated.rs.
Add GraphBuilder to build Graph instances, the methods can be chained on it in order to configure the graph conveniently.
Use the generic parameter type function for set_input and get_output, so users can use a lot of types as parameters, such as [f32], [u8], Vec<f32>, Vec<u8>, etc.
For Safety
Users cannot use raw pointers anymore.
Add a lifetime parameter for GraphExecutionContext, it cannot live longer than Graph.
Change the GraphExecutionContext as &mut self when running set_input and compute.
Misc
Update the example rust/examples/classification-example/src/main.rs to adapt the high-level API.
Add the documents for the library and structures, so the users can see them in docs.rs.
Set the build targets in Cargo.toml for docs.rs.
Add .cargo/config.toml to set the default build/publish target to wasm32-wasi.
This PR adds a wrapper high-level and safe rust API for the generated rust bindings.
The key changes
wasi_ephemeral_nn::*
.Details
For Convenience
Error
andBackendError
enum for error handling, and introduce a dependencythiserror
. (replaceNnErrno
)GraphEncoding
,ExecutionTarget
, andTensorType
enum to replace the corresponding types ingenerated.rs
.GraphBuilder
to buildGraph
instances, the methods can be chained on it in order to configure the graph conveniently.set_input
andget_output
, so users can use a lot of types as parameters, such as[f32]
,[u8]
,Vec<f32>
,Vec<u8>
, etc.For Safety
GraphExecutionContext
, it cannot live longer thanGraph
.GraphExecutionContext
as&mut self
when runningset_input
andcompute
.Misc
rust/examples/classification-example/src/main.rs
to adapt the high-level API.Cargo.toml
for docs.rs..cargo/config.toml
to set the default build/publish target towasm32-wasi
.This is a part work of WasmEdge's LFX mentorship, Thanks.