Add Send and Sync on Error Source (#118)

* Add Send and Sync on Error Source and remove 'static

* Add back 'static

* Update the changelog
This commit is contained in:
CosminPerRam 2023-10-09 19:11:34 +03:00 committed by GitHub
parent b7e1eff9b7
commit c8a93357cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View file

@ -3,6 +3,9 @@ Who knows what the future holds...
# 0.X.Y - DD/MM/YYYY # 0.X.Y - DD/MM/YYYY
### Changes: ### Changes:
Crate:
- Added `Send` and `Sync` on `Error::source` to fix some async issues.
Protocols: Protocols:
- Minecraft Java: Add derives to `RequestSettings` and add `new_just_hostname` that creates new settings just by specifying - 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. the hostname, `protocol_version` defaults to -1.

View file

@ -3,7 +3,7 @@ use std::error::Error;
use std::fmt::Formatter; use std::fmt::Formatter;
use std::{backtrace, fmt}; use std::{backtrace, fmt};
type ErrorSource = Box<dyn Error + 'static>; pub(crate) type ErrorSource = Box<dyn Error + 'static + Send + Sync>;
/// The GameDig error type. /// The GameDig error type.
/// ///
@ -54,7 +54,7 @@ impl PartialEq for GDError {
} }
impl Error 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 { 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 /// Create a new error using any type that can be converted to an error
pub fn from_error<E: Into<Box<dyn Error + 'static>>>(kind: GDErrorKind, source: E) -> Self { pub fn from_error<E: Into<ErrorSource>>(kind: GDErrorKind, source: E) -> Self {
Self::new(kind, Some(source.into())) Self::new(kind, Some(source.into()))
} }
} }

View file

@ -1,5 +1,5 @@
use crate::error::ErrorSource;
use crate::GDError; use crate::GDError;
use std::error::Error;
/// All GameDig Error kinds. /// All GameDig Error kinds.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
@ -44,7 +44,7 @@ impl GDErrorKind {
/// use gamedig::{GDErrorKind, GDResult}; /// use gamedig::{GDErrorKind, GDResult};
/// let _: GDResult<u32> = "thing".parse().map_err(|e| GDErrorKind::TypeParse.context(e)); /// let _: GDResult<u32> = "thing".parse().map_err(|e| GDErrorKind::TypeParse.context(e));
/// ``` /// ```
pub fn context<E: Into<Box<dyn Error + 'static>>>(self, source: E) -> GDError { GDError::from_error(self, source) } pub fn context<E: Into<ErrorSource>>(self, source: E) -> GDError { GDError::from_error(self, source) }
} }
#[cfg(test)] #[cfg(test)]