Hello.
I have a function for register Closure (C callback) - set_write_callback().
I would like send a message in callback body.
pub fn set_write_callback<T, Closure>(&mut self, callback: Closure)
-> Result<(), String>
where
Closure: FnMut(u32, T) -> Result<(), String>,
Closure: 'static + Sized,
Closure: panic::RefUnwindSafe,
T: std::fmt::Display + Default,
//...
var.set_write_callback::<bool, _>(move |p_arg, state |{
let value: u8;
if state { value = 1; } else { value = 0; }
address.do_send(PushData::new("Test".to_string(), value));
return Ok(());
}).expect("Error");
Error:
may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
error[E0277]: the type `std::cell::UnsafeCell<actix::address::channel::ReceiverTask>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
--> src/main.rs:215:25
|
215 | var.set_write_callback::<bool, _>(
| ^^^^^^^^^^^^^^^^^^ `std::cell::UnsafeCell<actix::address::channel::ReceiverTask>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
216 | / move |p_arg, state |{
... |
226 | | return Ok(());
227 | | }).expect("Error");
| |_________________________- within this `[closure@src/main.rs:216:25: 227:26 iec_var_name:std::string::String, address:actix::address::Addr<datahub::DataHub>]`
|
= help: within `[closure@src/main.rs:216:25: 227:26 iec_var_name:std::string::String, address:actix::address::Addr<datahub::DataHub>]`, the trait `std::panic::RefUnwindSafe` is not implemented for `std::cell::UnsafeCell<actix::address::channel::ReceiverTask>`
= note: required because it appears within the type `lock_api::mutex::Mutex<parking_lot::raw_mutex::RawMutex, actix::address::channel::ReceiverTask>`
= note: required because it appears within the type `actix::address::channel::Inner<datahub::DataHub>`
= note: required because it appears within the type `alloc::sync::ArcInner<actix::address::channel::Inner<datahub::DataHub>>`
= note: required because it appears within the type `std::marker::PhantomData<alloc::sync::ArcInner<actix::address::channel::Inner<datahub::DataHub>>>`
= note: required because it appears within the type `std::sync::Arc<actix::address::channel::Inner<datahub::DataHub>>`
= note: required because it appears within the type `actix::address::channel::AddressSender<datahub::DataHub>`
= note: required because it appears within the type `actix::address::Addr<datahub::DataHub>`
= note: required because it appears within the type `[closure@src/main.rs:216:25: 227:26 iec_var_name:std::string::String, address:actix::address::Addr<datahub::DataHub>]`
How to fix it?