From c8a93357cf2ec9edb0e51f17177b68408073dcba Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Mon, 9 Oct 2023 19:11:34 +0300 Subject: [PATCH] Add Send and Sync on Error Source (#118) * Add Send and Sync on Error Source and remove 'static * Add back 'static * Update the changelog --- CHANGELOG.md | 3 +++ src/errors/error.rs | 6 +++--- src/errors/kind.rs | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b7864b..a6c1f7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ Who knows what the future holds... # 0.X.Y - DD/MM/YYYY ### Changes: +Crate: +- Added `Send` and `Sync` on `Error::source` to fix some async issues. + Protocols: - Minecraft Java: Add derives to `RequestSettings` and add `new_just_hostname` that creates new settings just by specifying the hostname, `protocol_version` defaults to -1. diff --git a/src/errors/error.rs b/src/errors/error.rs index c2c2a36..582bbac 100644 --- a/src/errors/error.rs +++ b/src/errors/error.rs @@ -3,7 +3,7 @@ use std::error::Error; use std::fmt::Formatter; use std::{backtrace, fmt}; -type ErrorSource = Box; +pub(crate) type ErrorSource = Box; /// The GameDig error type. /// @@ -54,7 +54,7 @@ impl PartialEq for GDError { } impl Error for GDError { - fn source(&self) -> Option<&(dyn Error + 'static)> { self.source.as_ref().map(Box::as_ref) } + fn source(&self) -> Option<&(dyn Error + 'static)> { self.source.as_ref().map(|err| Box::as_ref(err) as _) } } impl fmt::Debug for GDError { @@ -88,7 +88,7 @@ impl GDError { } /// Create a new error using any type that can be converted to an error - pub fn from_error>>(kind: GDErrorKind, source: E) -> Self { + pub fn from_error>(kind: GDErrorKind, source: E) -> Self { Self::new(kind, Some(source.into())) } } diff --git a/src/errors/kind.rs b/src/errors/kind.rs index dff3be7..65c0d1b 100644 --- a/src/errors/kind.rs +++ b/src/errors/kind.rs @@ -1,5 +1,5 @@ +use crate::error::ErrorSource; use crate::GDError; -use std::error::Error; /// All GameDig Error kinds. #[derive(Debug, Clone, PartialEq, Eq)] @@ -44,7 +44,7 @@ impl GDErrorKind { /// use gamedig::{GDErrorKind, GDResult}; /// let _: GDResult = "thing".parse().map_err(|e| GDErrorKind::TypeParse.context(e)); /// ``` - pub fn context>>(self, source: E) -> GDError { GDError::from_error(self, source) } + pub fn context>(self, source: E) -> GDError { GDError::from_error(self, source) } } #[cfg(test)]