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

[eframe] Serde feature is broken #5278

Open
MeGaGiGaGon opened this issue Oct 17, 2024 · 1 comment
Open

[eframe] Serde feature is broken #5278

MeGaGiGaGon opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something is broken

Comments

@MeGaGiGaGon
Copy link
Contributor

Describe the bug
When using eframe, the "serde" feature doesn't work to enable serde derives on egui types, while "persistence" does work.
This only happens when importing through eframe, this doesn't happen when using egui directly.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new crate, in my case cargo new egui_serde_test
  2. Make the contents of cargo.toml
[package]
name = "egui_serde_test"
version = "0.1.0"
edition = "2021"

[patch.crates-io]
egui = { git = "https://github.com/emilk/egui", branch = "master" }
eframe = { git = "https://github.com/emilk/egui", branch = "master" }

[dependencies]
eframe = { version = "0.29.1", features = [ "serde" ] }
serde = { version = "1.0", features = [ "derive" ] }
  1. Make the contents of main.rs
#[derive(serde::Serialize)]
struct IdSerdeTest(eframe::egui::Id);

fn main() {
    println!("Hello, world!");
}
  1. Run cargo check
  2. Observe the "the trait bound Id: Serialize is not satisfied" error
full error message
error[E0277]: the trait bound `Id: Serialize` is not satisfied
   --> src/main.rs:1:10
    |
1   | #[derive(serde::Serialize)]
    |          ^^^^^^^^^^^^^^^^ the trait `Serialize` is not implemented for `Id`
2   | struct IdSerdeTest(eframe::egui::Id);
    |                    ------ required by a bound introduced by this call
    |
    = note: for local types consider adding `#[derive(serde::Serialize)]` to your `Id` type
    = note: for types from other crates check whether the crate offers a `serde` feature flag
    = help: the following other types implement trait `Serialize`:
              &'a T
              &'a mut T
              ()
              (T,)
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
            and 131 others
note: required by a bound in `serialize_newtype_struct`
   --> C:\Users\gigagon\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.210\src\ser\mod.rs:907:21
    |
901 |     fn serialize_newtype_struct<T>(
    |        ------------------------ required by a bound in this associated function
...
907 |         T: ?Sized + Serialize;
    |                     ^^^^^^^^^ required by this bound in `Serializer::serialize_newtype_struct`
    = note: this error originates in the derive macro `serde::Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `egui_serde_test` (bin "egui_serde_test") due to 1 previous error
  1. Switch "serde" to "persistence" in cargo.toml
  2. Run cargo check
  3. Observe no errors

Expected behavior
The "serde" feature enables serde trait derives on egui though eframe

Desktop (please complete the following information):

  • OS: Windows 10
@MeGaGiGaGon MeGaGiGaGon added the bug Something is broken label Oct 17, 2024
@YgorSouza
Copy link
Contributor

Should crates propagate serde to their re-exports when they don't need to? The API guidelines don't seem to make any recommendation on that. On the one hand it's practical, but on the other hand it takes some control away from the user. What if someone actually just wants to serialize WebGlContextOption and doesn't want to pay the price of compiling serde traits for all of egui's types?

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

No branches or pull requests

2 participants