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. }

9. enum Suit {
10. Clubs,
11. Diamonds,
12. Hearts,
13. Spades,
14. }
15. }
  • 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.