Shared Types

  1. #[cxx::bridge]
  2. mod ffi {
  3. #[derive(Clone, Debug, Hash)]
  4. struct PlayingCard {
  5. suit: Suit,
  6. value: u8, // A=1, J=11, Q=12, K=13
  7. }
  8. enum Suit {
  9. Clubs,
  10. Diamonds,
  11. Hearts,
  12. Spades,
  13. }
  14. }
  • Only C-like (unit) enums are supported.
  • A limited number of traits are supported for #[derive()] on shared types. Corresponding functionality is also generated for the C++ code, e.g. if you derive Hash also generates an implementation of std::hash for the corresponding C++ type.