From 99d6a56336c8c6e5a3e5fb9f132bb15157fc1525 Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 2 Dec 2021 00:52:24 +0300 Subject: Get rid of the unsafe code Thanks to @Kloenk I was able to get rid of the unsafety and tell the compiler how to properly check what I needed for the StorageError to be declared thread-safe. --- src/database/mod.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/database') diff --git a/src/database/mod.rs b/src/database/mod.rs index 4e74c8f..339439d 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -46,13 +46,10 @@ pub enum ErrorKind { #[derive(Debug)] pub struct StorageError { msg: String, - source: Option>, + source: Option>, kind: ErrorKind, } -// XXX figure out what makes this un-sendable by default -// and if it's sound to mark StorageError as Send & Sync -unsafe impl Send for StorageError {} -unsafe impl Sync for StorageError {} + impl From for tide::Response { fn from(err: StorageError) -> Self { tide::Response::builder(match err.kind() { @@ -73,7 +70,7 @@ impl From for tide::Response { } impl std::error::Error for StorageError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - self.source.as_ref().map(|e| e.as_ref()) + self.source.as_ref().map(|e| e.as_ref() as &dyn std::error::Error) } } impl From for StorageError { @@ -118,7 +115,7 @@ impl StorageError { } } /// Create a StorageError using another arbitrary Error as a source. - fn with_source(kind: ErrorKind, msg: &str, source: Box) -> Self { + fn with_source(kind: ErrorKind, msg: &str, source: Box) -> Self { Self { msg: msg.to_string(), source: Some(source), -- cgit 1.4.1