Skip to content

Conversation

jsen-
Copy link

@jsen- jsen- commented Mar 15, 2022

While working on JS <-> rust interop crate, I'm trying to serialize function arguments on the javascript side and deserialize into a tuple with appropriate number of elements on the rust side. Unfortunately I found that it doesn't work for functions with no arguments.

serde_json::from_str::<(u8,u8)>("[1, 2]").unwrap(); // is fine
serde_json::from_str::<(u8,)>("[1]").unwrap(); // is fine
serde_json::from_str::<()>("[]").unwrap(); // currently fails

This PR allows the last line to pass.

@andogq
Copy link

andogq commented Jul 26, 2025

I would also be interested in this feature being merged! I've run into the exact same use-case. Happy to assist with any contributions required to get this merged! :)

If anyone else is facing this issue, [(); 0] works as a stand-in for () and will happily deserialise from []: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=91e7fd458c369b2dd74e13d90ae2f03d

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

Successfully merging this pull request may close these issues.

2 participants