Skip to content

Commit

Permalink
fixed wrap-rust test case 002-object-types
Browse files Browse the repository at this point in the history
  • Loading branch information
krisbitney committed Jul 18, 2023
1 parent ba282eb commit b341fdd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::{
method_wrapped
};
use polywrap_wasm_rs::{
abort,
invoke,
Expand All @@ -13,6 +16,9 @@ pub extern "C" fn _wrap_invoke(method_size: u32, args_size: u32, env_size: u32)
let result: Vec<u8>;

match args.method.as_str() {
"method" => {
result = method_wrapped(args.args.as_slice(), env_size);
}
_ => {
invoke::wrap_invoke_error(format!("Could not find invoke function {}", args.method));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ pub mod custom_map_value;
pub use custom_map_value::CustomMapValue;
pub mod _else;
pub use _else::Else;
pub mod arg;
pub use arg::Arg;
pub mod nested;
pub use nested::Nested;
pub mod output;
pub use output::Output;

pub mod module;
pub use module::{
Module,
ModuleTrait,
method_wrapped,
ArgsMethod
};

// Override print!(...) & println!(...) macros
#[macro_export]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use polywrap_wasm_rs::{
JSON
};
use crate::{
ArgsMethod
ArgsMethod,
};
use crate::Arg;
use crate::Output;

pub struct Module;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ use polywrap_wasm_rs::{
};
use crate::module::{ModuleTrait, Module};
use crate::Arg;
use crate::Output;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ArgsMethod {
pub arg: Arg
pub arg: Arg,
}

pub fn method_wrapped(args: &[u8], env_size: u32) -> Vec<u8> {
match from_slice::<ArgsMethod>(args) {
Ok(args) => {
let result = Module::method1(ArgsMethod {
arg: args.arg
let result = Module::method(ArgsMethod {
arg: args.arg,
});
match result {
Ok(res) => {
Expand All @@ -39,4 +40,4 @@ pub fn method_wrapped(args: &[u8], env_size: u32) -> Vec<u8> {
panic!("{}", e.to_string())
}
}
}
}

0 comments on commit b341fdd

Please sign in to comment.