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

Added support for VectorIntoWasmAbi and VectorFromWasmAbi #41

Merged
merged 12 commits into from
Aug 5, 2024

Conversation

eneoli
Copy link

@eneoli eneoli commented Aug 1, 2024

In this pull request (see also: this related issue), the capability to return a Vec<SomeType> was introduced to wasm-bindgen, where SomeType has the #[wasm_bindgen] attribute.

This PR further extends this capability to support returning Vec<SomeType> where SomeType derives Tsify. This is done by implementing VectorIntoWasmAbi and VectorFromWasmAbi introduced in the linked PR.

Two new attributes were added to control whether the above traits should be implemented.

Example:

#[derive(Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
#[serde(tag = "kind", content = "value")]
pub enum Pet {
    Cat(String),
    Dog(String),
}

#[wasm_bindgen]
pub fn return_pets() -> Vec<Pet> {
    vec![Pet::Cat("Pumpkin"), Pet::Dog("Cookie")]
}

#[wasm_bindgen]
pub fn read_pets(pets: Vec<Pet>) {
    // ...
}

@eneoli
Copy link
Author

eneoli commented Aug 1, 2024

@siefkenj Sorry for the noise. I had an old clippy installed that did not detect the dead code. This also probably explains why the CI did not nag when this code was added first. (The dead code is unrelated to the PR.)

@siefkenj
Copy link
Owner

siefkenj commented Aug 1, 2024

Thank you for the contribution! I will review it as soon as I can :-)

@siefkenj
Copy link
Owner

siefkenj commented Aug 1, 2024

Is there a reason to put these behind a flag? Would it cause problems if into_wasm_abi implied vector_into_wasm_abi? (I would think that would be the default expected behavior)

Could you please add some tests to this PR?

@@ -14,8 +12,6 @@ pub struct TsifyContainerAttrs {
pub namespace: bool,
/// Information about how the type should be serialized.
pub ty_config: TypeGenerationConfig,
/// Comments associated with the type. These will be written out to the generated Typescript.
pub comments: Vec<String>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these comments not being used? Why was this field removed?

Copy link
Author

@eneoli eneoli Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, the static code analysis (clippy) reported that this field was never read. That was also one of the reasons the CI failed.

tests-e2e/test1/entry_point.rs Outdated Show resolved Hide resolved
@eneoli eneoli requested a review from siefkenj August 4, 2024 11:07
@siefkenj siefkenj merged commit 9277dd5 into siefkenj:main Aug 5, 2024
3 checks passed
@siefkenj
Copy link
Owner

siefkenj commented Aug 5, 2024

Thanks for your effort!

@eneoli
Copy link
Author

eneoli commented Aug 5, 2024

Thank you for merging my pull request!

Could you please also publish a new release that includes these changes?

@siefkenj
Copy link
Owner

siefkenj commented Aug 5, 2024

Done :-)

@eneoli eneoli deleted the add-vector-abi-support branch August 5, 2024 20:16
@Pantamis
Copy link

Pantamis commented Aug 8, 2024

Thank you so much !

This is really great stuff ! I was just missing this XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants