0

I am using bindgen to generate code with the following config.

let mut builder = bindgen::Builder::default()
    .clang_arg("-std=c++11")
    .clang_arg("-x")
    .clang_arg("c++")
    .clang_arg("-Wno-pragma-once-outside-header")
    .layout_tests(false)
    .derive_copy(true)
    .enable_cxx_namespaces()
    .default_enum_style(EnumVariation::Rust {
        non_exhaustive: false,
    });

However I find that the generated code like

#[derive(Debug, Copy, Clone)]
pub struct RawCppPtr {
    pub ptr: root::DB::RawVoidPtr,
    pub type_: root::DB::RawCppPtrType,
}

I wonder if there are any ways that I can only generate #[derive(Clone)] without generating [derive(Copy)]?

calvin
  • 2,125
  • 2
  • 21
  • 38
  • What will happen if your remove `.derive_copy(true)` from your config, or set it to `false` ? – Svetlin Zarev Sep 02 '21 at 13:12
  • @SvetlinZarev There will be neither Copy nor Clone. – calvin Sep 02 '21 at 13:14
  • You are probably able to do that by combining [`Builder::parse_callbacks()`](https://docs.rs/bindgen/0.59.1/bindgen/struct.Builder.html#method.parse_callbacks) and [`ParseCallbacks::add_derives()`](https://docs.rs/bindgen/0.59.1/bindgen/callbacks/trait.ParseCallbacks.html#method.add_derives), though I haven't tested this. – Elias Holzmann Sep 02 '21 at 13:47
  • 3
    I'm not sure that it makes sense to derive `Clone` without also deriving `Copy` in this context. After all `Copy` is just a marker trait that tells the compiler that `clone` is just a bitwise copy without any extra logic. In the case of an FFI structure, I don't see how `derive(Clone)` could be anything else than a bitwise copy… – Jmb Sep 02 '21 at 14:37

0 Answers0