use Box instead of Cell

This commit is contained in:
Fl1tzi 2023-05-20 11:40:17 +02:00
parent 366b08c850
commit 7edb88192c
3 changed files with 5 additions and 6 deletions

View file

@ -8,7 +8,7 @@ use hidapi::HidApi;
use std::{
collections::HashMap,
fmt::Display,
sync::Arc, cell::Cell,
sync::Arc,
};
use streamdeck::{
asynchronous::{AsyncStreamDeck, ButtonStateUpdate},
@ -106,7 +106,7 @@ impl Device {
let b = btn.clone();
runtime.spawn(async move {
start_module(ser, b, module, dev, Cell::new(button_receiver)).await
start_module(ser, b, module, dev, Box::new(button_receiver)).await
});
}
self.modules

View file

@ -8,7 +8,6 @@ pub use deck_driver as streamdeck;
use futures_util::Future;
use image::DynamicImage;
use lazy_static::lazy_static;
use std::cell::Cell;
use std::collections::HashMap;
use std::pin::Pin;
use std::{error::Error, sync::Arc};
@ -51,7 +50,7 @@ pub async fn start_module(
button: Arc<Button>,
module_function: ModuleFunction,
device: Arc<AsyncStreamDeck>,
br: Cell<mpsc::Receiver<HostEvent>>
br: ChannelReceiver
) {
debug!("STARTED");
let da = DeviceAccess::new(device, button.index).await;
@ -110,7 +109,7 @@ impl DeviceAccess {
}
pub type ReturnError = Box<dyn Error + Send + Sync>;
pub type ChannelReceiver = Cell<mpsc::Receiver<HostEvent>>;
pub type ChannelReceiver = Box<mpsc::Receiver<HostEvent>>;
#[async_trait]
pub trait Module {

View file

@ -20,7 +20,7 @@ impl Module for Counter {
button_receiver: ChannelReceiver,
_config: Arc<Button>,
) -> Result<(), ReturnError> {
let mut button_receiver = button_receiver.into_inner();
let mut button_receiver = button_receiver;
let font_data: &[u8] = include_bytes!("../../fonts/SpaceGrotesk.ttf");
let font: Font<'static> = Font::try_from_bytes(font_data).unwrap();