rust-bindgen

How do I convert a static global variable generated by Bindgen into a global const?

☆樱花仙子☆ 提交于 2021-01-29 11:54:40
问题 Bindgen generates this from a static const C-style global structure: pub struct rmw_qos_profile_t { pub depth: usize, pub deadline: rmw_time_t, // ... } extern "C" { #[link_name = "\u{1}rmw_qos_profile_sensor_data"] pub static rmw_qos_profile_sensor_data: rmw_qos_profile_t; } I would like to safely bind it to a global const in Rust. My best attempt so far is impl From<rmw_qos_profile_t> for QoSProfile { fn from(qos_profile: rmw_qos_profile_t) -> Self { QoSProfile { depth: qos_profile.depth,

How to properly wrap a C function pointer in Rust? [duplicate]

自闭症网瘾萝莉.ら 提交于 2020-07-19 05:58:09
问题 This question already has answers here : Why does the address of an object change across methods? (2 answers) Closed 4 months ago . I have a C struct Foo with a function pointer. In my Rust bindings, I would like to allow users to set this function pointer, but I would like to avoid users having to deal with FFI types. foo.h struct Foo { void* internal; uint8_t a; void (*cb_mutate_a)(void*); }; struct Foo* foo_new(); void foo_free(struct Foo* foo); void foo_call(struct Foo* foo); foo.c struct

How to properly wrap a C function pointer in Rust? [duplicate]

走远了吗. 提交于 2020-07-19 05:58:08
问题 This question already has answers here : Why does the address of an object change across methods? (2 answers) Closed 4 months ago . I have a C struct Foo with a function pointer. In my Rust bindings, I would like to allow users to set this function pointer, but I would like to avoid users having to deal with FFI types. foo.h struct Foo { void* internal; uint8_t a; void (*cb_mutate_a)(void*); }; struct Foo* foo_new(); void foo_free(struct Foo* foo); void foo_call(struct Foo* foo); foo.c struct