melib: remove unnecessary unsafe impls
parent
89b1e381dc
commit
84a042411d
|
@ -36,7 +36,7 @@ use std::fmt;
|
|||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Work(pub Arc<Box<dyn Fn() -> ()>>);
|
||||
pub struct Work(pub Arc<Box<dyn Fn() -> () + Send + Sync>>);
|
||||
|
||||
impl Work {
|
||||
pub fn compute(&self) {
|
||||
|
@ -50,9 +50,6 @@ impl fmt::Debug for Work {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for Work {}
|
||||
unsafe impl Sync for Work {}
|
||||
|
||||
/// Messages to pass between `Async<T>` owner and its worker thread.
|
||||
#[derive(Clone)]
|
||||
pub enum AsyncStatus<T> {
|
||||
|
@ -76,13 +73,13 @@ impl<T> fmt::Debug for AsyncStatus<T> {
|
|||
|
||||
/// A builder object for `Async<T>`
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AsyncBuilder<T> {
|
||||
pub struct AsyncBuilder<T: Send + Sync> {
|
||||
tx: chan::Sender<AsyncStatus<T>>,
|
||||
rx: chan::Receiver<AsyncStatus<T>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Async<T> {
|
||||
pub struct Async<T: Send + Sync> {
|
||||
value: Option<T>,
|
||||
work: Work,
|
||||
active: bool,
|
||||
|
@ -90,13 +87,16 @@ pub struct Async<T> {
|
|||
rx: chan::Receiver<AsyncStatus<T>>,
|
||||
}
|
||||
|
||||
impl<T> Default for AsyncBuilder<T> {
|
||||
impl<T: Send + Sync> Default for AsyncBuilder<T> {
|
||||
fn default() -> Self {
|
||||
AsyncBuilder::<T>::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AsyncBuilder<T> {
|
||||
impl<T> AsyncBuilder<T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
let (sender, receiver) = chan::sync(8 * ::std::mem::size_of::<AsyncStatus<T>>());
|
||||
AsyncBuilder {
|
||||
|
@ -113,7 +113,7 @@ impl<T> AsyncBuilder<T> {
|
|||
self.rx.clone()
|
||||
}
|
||||
/// Returns an `Async<T>` object that contains a `Thread` join handle that returns a `T`
|
||||
pub fn build(self, work: Box<dyn Fn() -> ()>) -> Async<T> {
|
||||
pub fn build(self, work: Box<dyn Fn() -> () + Send + Sync>) -> Async<T> {
|
||||
Async {
|
||||
work: Work(Arc::new(work)),
|
||||
value: None,
|
||||
|
@ -124,7 +124,10 @@ impl<T> AsyncBuilder<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Async<T> {
|
||||
impl<T> Async<T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
/// Consumes `self` and returns the computed value. Will panic if computation hasn't finished.
|
||||
pub fn extract(self) -> T {
|
||||
self.value.unwrap()
|
||||
|
|
|
@ -111,11 +111,9 @@ impl RefreshEvent {
|
|||
/// A `RefreshEventConsumer` is a boxed closure that must be used to consume a `RefreshEvent` and
|
||||
/// send it to a UI provided channel. We need this level of abstraction to provide an interface for
|
||||
/// all users of mailbox refresh events.
|
||||
pub struct RefreshEventConsumer(Box<Fn(RefreshEvent) -> ()>);
|
||||
unsafe impl Send for RefreshEventConsumer {}
|
||||
unsafe impl Sync for RefreshEventConsumer {}
|
||||
pub struct RefreshEventConsumer(Box<Fn(RefreshEvent) -> () + Send + Sync>);
|
||||
impl RefreshEventConsumer {
|
||||
pub fn new(b: Box<Fn(RefreshEvent) -> ()>) -> Self {
|
||||
pub fn new(b: Box<Fn(RefreshEvent) -> () + Send + Sync>) -> Self {
|
||||
RefreshEventConsumer(b)
|
||||
}
|
||||
pub fn send(&self, r: RefreshEvent) {
|
||||
|
@ -123,9 +121,7 @@ impl RefreshEventConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct NotifyFn(Box<Fn(FolderHash) -> ()>);
|
||||
unsafe impl Send for NotifyFn {}
|
||||
unsafe impl Sync for NotifyFn {}
|
||||
pub struct NotifyFn(Box<Fn(FolderHash) -> () + Send + Sync>);
|
||||
|
||||
impl fmt::Debug for NotifyFn {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -133,14 +129,14 @@ impl fmt::Debug for NotifyFn {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Box<Fn(FolderHash) -> ()>> for NotifyFn {
|
||||
fn from(kind: Box<Fn(FolderHash) -> ()>) -> Self {
|
||||
impl From<Box<Fn(FolderHash) -> () + Send + Sync>> for NotifyFn {
|
||||
fn from(kind: Box<Fn(FolderHash) -> () + Send + Sync>) -> Self {
|
||||
NotifyFn(kind)
|
||||
}
|
||||
}
|
||||
|
||||
impl NotifyFn {
|
||||
pub fn new(b: Box<Fn(FolderHash) -> ()>) -> Self {
|
||||
pub fn new(b: Box<Fn(FolderHash) -> () + Send + Sync>) -> Self {
|
||||
NotifyFn(b)
|
||||
}
|
||||
pub fn notify(&self, f: FolderHash) {
|
||||
|
@ -297,7 +293,7 @@ pub fn folder_default() -> Folder {
|
|||
}
|
||||
|
||||
pub type FolderHash = u64;
|
||||
pub type Folder = Box<dyn BackendFolder + Send>;
|
||||
pub type Folder = Box<dyn BackendFolder + Send + Sync>;
|
||||
|
||||
impl Clone for Folder {
|
||||
fn clone(&self) -> Self {
|
||||
|
|
Loading…
Reference in New Issue