Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support OptionFromWasmAbi for &T #3754

Open
rouzwelt opened this issue Dec 24, 2023 · 0 comments
Open

support OptionFromWasmAbi for &T #3754

rouzwelt opened this issue Dec 24, 2023 · 0 comments

Comments

@rouzwelt
Copy link

rouzwelt commented Dec 24, 2023

Motivation

As someone who has recently learned wasm-bindgen, something that keeps bothering me is that OptionFromWasmAbi, OptionIntoWasmAbi wont get implemented for struct, and I always need to work around that.
for example let's say there is some struct:

#[wasm-bindgen]
pub struct SomeStruct;

and when using that as an argument of some fn, there is no issue with having that as either of Option<SomeStruct> or &SomeStruct, but when using it as Option<&SomeStruct> there are compiler complaints.

#[wasm-bindgen]
pub fn some_fn(value: Option<&SomeStruct>) {
    // fn body
}

with this error:

the trait bound &SomeStruct: OptionFromWasmAbi is not satisfied
the trait OptionFromWasmAbi is implemented for SomeStruct
required for std::option::Option<&SomeStruct> to implement FromWasmAbi

having that can be usefull in cases where we dont want/need the ownership to be transfered to the underlying function and also want to keep that argument as an Option

Proposed Solution

As I stated earlier Im pretty new to wasm-bindgen, so there might be some easy workaround/solution for this out there already, if so, it would be great that someone can point it out here so someone like me and possibly others can benefit from, but as far asI searched I could not find any standard solution for this.

@rouzwelt rouzwelt changed the title support OptionFromWasmAbi, OptionIntoWasmAbi for &T support OptionFromWasmAbi for &T Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant