From 4db82ad2c80e684a4b5d2ac437afa70f5e63f83e Mon Sep 17 00:00:00 2001 From: Trivernis Date: Wed, 13 Jan 2021 11:36:14 +0100 Subject: [PATCH] Add inner value for SendError to Error type field Signed-off-by: Trivernis --- Cargo.toml | 2 +- src/executor/stream.rs | 10 +++------- src/utils/result.rs | 13 ++++++++++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eb45628..d675e8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ description = "OpenCL Stream execution framework" repository = "https://github.com/parallel-programming-hwr/ocl-stream-rs" license = "Apache-2.0" readme = "README.md" -version = "0.3.2" +version = "0.3.3" authors = ["Trivernis "] edition = "2018" diff --git a/src/executor/stream.rs b/src/executor/stream.rs index d9c57d5..000dec3 100644 --- a/src/executor/stream.rs +++ b/src/executor/stream.rs @@ -79,19 +79,15 @@ where impl OCLStreamSender where - T: Send + Sync, + T: Send + Sync + 'static, { /// Sends a value into the channel pub fn send(&self, value: T) -> OCLStreamResult<()> { - self.tx - .send(Ok(value)) - .map_err(|_| OCLStreamError::SendError) + self.tx.send(Ok(value)).map_err(OCLStreamError::from) } /// Sends an error into the channel pub fn err(&self, err: OCLStreamError) -> OCLStreamResult<()> { - self.tx - .send(Err(err)) - .map_err(|_| OCLStreamError::SendError) + self.tx.send(Err(err)).map_err(OCLStreamError::from) } } diff --git a/src/utils/result.rs b/src/utils/result.rs index 705af26..01f753d 100644 --- a/src/utils/result.rs +++ b/src/utils/result.rs @@ -5,6 +5,8 @@ */ use crossbeam_channel::RecvError; +use crossbeam_channel::SendError; +use std::error::Error; use thiserror::Error; pub type OCLStreamResult = Result; @@ -18,7 +20,7 @@ pub enum OCLStreamError { RecvError(#[from] RecvError), #[error("Stream Send Error")] - SendError, + SendError(#[from] Box), } impl From for OCLStreamError { @@ -26,3 +28,12 @@ impl From for OCLStreamError { Self::OCLError(format!("{}", e)) } } + +impl From> for OCLStreamError +where + T: Send + Sync, +{ + fn from(e: SendError) -> Self { + Self::SendError(Box::new(e)) + } +}