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

Specify the discriminant for enum variants #109

Open
desm86 opened this issue Aug 8, 2023 · 2 comments
Open

Specify the discriminant for enum variants #109

desm86 opened this issue Aug 8, 2023 · 2 comments

Comments

@desm86
Copy link

desm86 commented Aug 8, 2023

#[repr(u8)]
#[derive(Serialize, Deserialize)]
pub enum Enum {
	Variant1(...),
	Variant3(...) = 2
}

Expected result:

Enum::Variant3(...) -> [2, ...]
@jamesmunns
Copy link
Owner

Hi there @desm86, as far as I am aware: serde doesn't actually use the discriminant value, even if it is specified like this.

Serde provides an integer that is the zero-indexed item, so in your example Variant1 will always be 0 and Variant3 will always be 1.

This is not something postcard can address, unless I am mistaken.

@33KK
Copy link

33KK commented Sep 7, 2023

Would this PR be relevant? serde-rs/serde#2354

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

No branches or pull requests

3 participants