wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

Rust: How do I return a list<string>?

Open juliusl opened this issue 1 year ago • 3 comments

Given .wit like this

package example:q

world test { 
  export hello: func() -> list<string>;
}

and impl in rs:

wit_bindgen::generate!({
	world: "test",
});

struct Test;

impl Guest for Test { 
	fn hello() -> Vec<String> {
		vec!["hello".to_string(), "world".to_string()]
	}
}
export!(test);

When I debug, the result is an empty array. Tried basically the same thing as above in this sample https://github.com/microsoft/vscode-extension-samples/tree/main/wasm-component-model w/ the same result.

I feel like I'm missing something fundamental here.

juliusl avatar May 25 '24 20:05 juliusl

Thanks for the report! Are you able to share how this code is being called? What you're doing looks correct so the mistake may be on the host half rather than the guest half perhaps?

alexcrichton avatar May 28 '24 14:05 alexcrichton

@alexcrichton hello yes I am using this sample, https://github.com/microsoft/vscode-extension-samples/tree/main/wasm-component-model

I added the hello function I defined in my issue to the calculator sample and then invoked it from the api object inside of the vscode command invocation. I can try to build an isolated example if that helps.

juliusl avatar Jun 03 '24 22:06 juliusl

Yeah if you can build an isolated example that'd be great! Sorry I'm not familiar with vscode extensions so I'm not sure precisely how the component is being run.

alexcrichton avatar Jun 04 '24 14:06 alexcrichton