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

Make io related enums to support serde Serialize/Deserialize #769

Open
ruby3141 opened this issue Mar 27, 2024 · 3 comments
Open

Make io related enums to support serde Serialize/Deserialize #769

ruby3141 opened this issue Mar 27, 2024 · 3 comments

Comments

@ruby3141
Copy link

Is your feature request related to a problem? Please describe.

Because imgui::Key does not support serde, this kind of thing is not possible.

use serde::{Deserialize, Serialize};
use imgui::Key;

#[derive(Serialize, Deserialize)]
pub struct HoykeyConfig {
    some_hotkey: Key,
    // ...
}

Providing proxy enum to use #[serde(remote="...")] is kind of viable, but not recommendable since imgui::Key has 140 entries.

Describe the solution you'd like

Make io related enums of this crate to derive serde::{Serialize, Deserialize}.

ruby3141 added a commit to ruby3141/DJMAXPlus that referenced this issue Mar 27, 2024
@sanbox-irl
Copy link
Member

We've been historically avoiding adding serde directly because we don't really have control over these types -- fundamentally they could change in a way that breaks serde compatibility.

How do you feel about making a proxy type (ie, Foo: From<imgui::Key>)?

@ruby3141
Copy link
Author

I already did, with huge chunk of copy-pasted enum definition.
It is working, but I'm still wonder if there's other way to achieve it without copy-paste.

@sanbox-irl
Copy link
Member

Since Rust promises the pattern-patching will always be exhaustive, I do think that your approach is actually future proofed. Annoying, yes, but future proofed.

I do the same thing with the imgui style settings for the same reason as above. For what it's worth, the reasoning that "because imgui controls this type means we can't serde it" is weak imo. If there's sufficient interest in trying, I'd probably try!

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

2 participants