0

I am trying to serialize some data in a struct in order to save it in a file, but the struct contains the type: macroquad::input::KeyCode
This type currently does not implement the macro I am trying to use, is there any way to get around this?

here is the specific struct

#[derive(Savefile)] // error ! the trait bound `macroquad::input::KeyCode: Serialize` is not satisfied
pub struct UserData {
    pub left: KeyCode,
    pub right: KeyCode,
    pub up: KeyCode,
    pub down: KeyCode,
    pub ability_key: [KeyCode; 5],
    pub abilities: [Abilities; 5],
    pub texture: String,
}
Ollie Lynas
  • 171
  • 9
  • 1
    Is it local? If yes, you can manually impl `Savefile`. If not, this question depends on the specific macro used, and you need to elaborate. – Chayim Friedman Aug 12 '22 at 10:57
  • It is not local, it is from the package macroquad, and the macro is from a package called savefile – Ollie Lynas Aug 12 '22 at 11:05
  • 1
    Then what is the `Savefile` macro? – Chayim Friedman Aug 12 '22 at 11:05
  • 1
    Can you use `Serialize` instead of `Savefile`? If you do, you can annotate the `KeyCode` fields with [`serialize_with`](https://serde.rs/field-attrs.html#serialize_with) to define a custom function for use when saving those fields. – Jmb Aug 12 '22 at 12:30

0 Answers0