dtolnay/cxx

Better integration between derives and operator overloads

开放

#109 创建于 2020年4月11日

 (5 条评论) (0 个反应) (0 位负责人)Rust (253 个派生)batch import
help wanted

仓库指标

星标
 (4,472 个星标)
PR 合并指标
 (平均合并 8分钟) (30 天内合并 3 个 PR)

描述

Many integration opportunities here.

  • If a shared struct has a #[derive(PartialEq or Ord)] then emit a compatible operator ==, operator !=, operator <, operator <=, operator >, operator >= on the type for C++.

    mod ffi {
        #[derive(PartialEq)]
        struct Key {
            n: usize,
        }
    }
    
  • If an opaque Rust type is written with trait bounds then wire up the corresponding operator for C++ in a way that delegates to Rust's implementation of the operator.

    mod ffi {
        extern "Rust" {
            type R: PartialEq;
        }
    }
    
    struct R {...}
    impl PartialEq for R {...}
    
  • If an opaque C++ type is written with trait bounds then produce a trait impl in Rust that delegates to the corresponding overloaded operator(s) in C++.

    mod ffi {
        extern "C++" {
            type C: PartialEq;  // produce a PartialEq that calls `operator ==`
        }
    }
    

贡献者指南