I'm trying to add a channel to the CoAP server handle:
use coap::{CoAPRequest, CoAPResponse, CoAPServer};
use std::sync::mpsc;
use std::sync::mpsc::{Receiver, Sender};
fn request_handler(request: CoAPRequest, channel_tx : Sender<u8>) -> Option<CoAPResponse> {
None
}
fn main() {
let addr = "[::]:5683";
let mut server = CoAPServer::new(addr).unwrap();
let (channel_tx, channel_rx): (Sender<u8>, Receiver<u8>) = mpsc::channel();
server.handle( move |request| {
request_handler(request, channel_tx.clone())
}).unwrap();
}
This does not work:
error[E0277]: `std::sync::mpsc::Sender<u8>` cannot be shared between threads safely
--> src/main.rs:14:12
|
14 | server.handle( move |request| {
| ^^^^^^ `std::sync::mpsc::Sender<u8>` cannot be shared between threads safely
|
= help: within `[closure@src/main.rs:14:20: 16:6 channel_tx:std::sync::mpsc::Sender<u8>]`, the trait `std::marker::Sync` is not implemented for `std::sync::mpsc::Sender<u8>`
= note: required because it appears within the type `[closure@src/main.rs:14:20: 16:6 channel_tx:std::sync::mpsc::Sender<u8>]`
= note: required because of the requirements on the impl of `coap::server::CoAPHandler` for `[closure@src/main.rs:14:20: 16:6 channel_tx:std::sync::mpsc::Sender<u8>]`
error[E0277]: the trait bound `std::sync::mpsc::Sender<u8>: std::marker::Copy` is not satisfied in `[closure@src/main.rs:14:20: 16:6 channel_tx:std::sync::mpsc::Sender<u8>]`
--> src/main.rs:14:12
|
14 | server.handle( move |request| {
| ^^^^^^ within `[closure@src/main.rs:14:20: 16:6 channel_tx:std::sync::mpsc::Sender<u8>]`, the trait `std::marker::Copy` is not implemented for `std::sync::mpsc::Sender<u8>`
|
= note: required because it appears within the type `[closure@src/main.rs:14:20: 16:6 channel_tx:std::sync::mpsc::Sender<u8>]`
= note: required because of the requirements on the impl of `coap::server::CoAPHandler` for `[closure@src/main.rs:14:20: 16:6 channel_tx:std::sync::mpsc::Sender<u8>]`
How to solve this?