Bindgen генерирует это из глобальной структуры в стиле static const
C:
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;
}
Я хотел бы безопасно связать его с глобальным const
в Rust.
Моя лучшая попытка на данный момент -
impl From<rmw_qos_profile_t> for QoSProfile {
fn from(qos_profile: rmw_qos_profile_t) -> Self {
QoSProfile {
depth: qos_profile.depth,
deadline: qos_profile.deadline.into(),
// ...
}
}
}
pub const QOS_PROFILE_SENSOR_DATA: QoSProfile = unsafe { rmw_qos_profile_sensor_data.into() };
Я получаю следующую ошибку компиляции:
error[E0013]: constants cannot refer to statics, use a constant instead
--> /home/deb0ch/ros2_rust_ws/install/rclrs/share/rclrs/rust/src/qos.rs:130:58
|
130 | pub const QOS_PROFILE_SENSOR_DATA: QoSProfile = unsafe { rmw_qos_profile_sensor_data.into() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> /home/deb0ch/ros2_rust_ws/install/rclrs/share/rclrs/rust/src/qos.rs:130:58
|
130 | pub const QOS_PROFILE_SENSOR_DATA: QoSProfile = unsafe { rmw_qos_profile_sensor_data.into() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0507]: cannot move out of static item `rmw_qos_profile_sensor_data`
--> /home/deb0ch/ros2_rust_ws/install/rclrs/share/rclrs/rust/src/qos.rs:130:58
|
130 | pub const QOS_PROFILE_SENSOR_DATA: QoSProfile = unsafe { rmw_qos_profile_sensor_data.into() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because `rmw_qos_profile_sensor_data` has type `rcl_bindings::rcl_bindings::rmw_qos_profile_t`, which does not implement the `Copy` trait
Как я могу go об этом?