生成的 C++ 代码

  1. #[cxx::bridge]
  2. mod ffi {
  3. // Rust types and signatures exposed to C++.
  4. extern "Rust" {
  5. type MultiBuf;
  6. fn next_chunk(buf: &mut MultiBuf) -> &[u8];
  7. }
  8. }

大致生成以下 C++:

  1. struct MultiBuf final : public ::rust::Opaque {
  2. ~MultiBuf() = delete;
  3. private:
  4. friend ::rust::layout;
  5. struct layout {
  6. static ::std::size_t size() noexcept;
  7. static ::std::size_t align() noexcept;
  8. };
  9. };
  10. ::rust::Slice<::std::uint8_t const> next_chunk(::org::blobstore::MultiBuf &buf) noexcept;