Skip to content

Decoupling new type mappings from the cxx crate #251

Open
@anforowicz

Description

@anforowicz

Hello,

Thank you for all the work on the cxx crate. I am sorry for a not very specific nor constructive issue, but I was wondering what it would take to decouple individual type mappings (e.g. std::vector<T> to CxxVector<T>, std::map<K, V> to TBD<K, V>, etc.) from the cxx crate itself. In particular, some projects have their own container implementations (e.g. Boost''s flat_map or Chromium's small_map or WebKit's WTF::Vector) or string implementations (e.g. WebKit's 16-bit String). It would be great if such projects could extend cxx with the extra mappings, without having to modify the cxx crate itself. AFAIU cxx already supports translating std::string and std::vector and plans to support std::map and std::unordered_map, but obviously would probably dislike having knowledge of Boost's, Chromium's or WebKit's types.

Could you please offer any feedback / thoughts on the above?

  • It is unclear to me how one would declare that a given C++ type should be recognized and wrapped in a specific way in Rust. Specifying the C++ type via its namespace-qualified name is definitely one possible way, but maybe some form of duck-typing is also desirable (handwaving: if a C++ type has begin and end methods, then it is wrapped as std::iter::Iterator or as IntoIterator; if it quacks like a drop-in replacement for std::map, then it is wrapped as CxxMap; etc);

  • It is unclear to me exactly which C++ => Rust type mappings would need to remain in the core cxx (even if they don't need to be in cxx and could be decoupled for design/hygiene reasons, we might still want to keep all the std library types close to cxx, to promote one canonical std => Rust type mapping).

    • I guess UniquePtr would remain in the core.
    • I am not sure about CxxString and CxxVector.
  • It is unclear to me how extensible type mappings impact with the safety guarantees of cxx and Rust.

/cc @adetaylor

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions