mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
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:
parent
b7e1eff9b7
commit
c8a93357cf
3 changed files with 8 additions and 5 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::error::Error;
|
|||
use std::fmt::Formatter;
|
||||
use std::{backtrace, fmt};
|
||||
|
||||
type ErrorSource = Box<dyn Error + 'static>;
|
||||
pub(crate) type ErrorSource = Box<dyn Error + 'static + Send + Sync>;
|
||||
|
||||
/// 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<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()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<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)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue