I use bindgen to create the rust bindings for a C-API.
For the generated binding code looks like this:
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct clingo_model {
_unused: [u8; 0],
}
#[doc = "! Object representing a model."]
pub type clingo_model_t = clingo_model;
In my library i create a newtype:
#[derive(Debug, Copy, Clone)]
pub struct Model(clingo_model_t);
When I try to clone a model something goes wrong. If i try to invoke a method on the clone i get a segfault.
...
println!("1:{:?}", model);
println!("number : {}", model.number().unwrap());
let model2 = model.clone();
println!("2:{:?}", model2);
println!("number : {}", model2.number().unwrap());
See the test case here.
Has anyone an idea why and maybe how to fix it?